Graph Execution Error and Un identified Image Error


UnknownError Traceback (most recent call last)
in <cell line: 6>()
4 # Train the model
5 # Note that this may take some time.
----> 6 history = model.fit(train_generator,
7 epochs=15,
8 verbose=1,

1 frames
/usr/local/lib/python3.10/dist-packages/tensorflow/python/eager/execute.py in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name)
50 try:
51 ctx.ensure_initialized()
—> 52 tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
53 inputs, attrs, num_outputs)
54 except core._NotOkStatusException as e:

UnknownError: Graph execution error:

2 root error(s) found.
(0) UNKNOWN: UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x7f7cad00a7f0>
Traceback (most recent call last):

File “/usr/local/lib/python3.10/dist-packages/tensorflow/python/ops/script_ops.py”, line 267, in call
ret = func(*args)

File “/usr/local/lib/python3.10/dist-packages/tensorflow/python/autograph/impl/api.py”, line 642, in wrapper
return func(*args, **kwargs)

File “/usr/local/lib/python3.10/dist-packages/tensorflow/python/data/ops/from_generator_op.py”, line 198, in generator_py_func
values = next(generator_state.get_iterator(iterator_id))

File “/usr/local/lib/python3.10/dist-packages/keras/engine/data_adapter.py”, line 902, in wrapped_generator
for data in generator_fn():

File “/usr/local/lib/python3.10/dist-packages/keras/engine/data_adapter.py”, line 1049, in generator_fn
yield x[i]

File “/usr/local/lib/python3.10/dist-packages/keras/preprocessing/image.py”, line 116, in getitem
return self._get_batches_of_transformed_samples(index_array)

File “/usr/local/lib/python3.10/dist-packages/keras/preprocessing/image.py”, line 370, in _get_batches_of_transformed_samples
img = image_utils.load_img(

File “/usr/local/lib/python3.10/dist-packages/keras/utils/image_utils.py”, line 423, in load_img
img = pil_image.open(io.BytesIO(f.read()))

File “/usr/local/lib/python3.10/dist-packages/PIL/Image.py”, line 3030, in open
raise UnidentifiedImageError(

PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x7f7cad00a7f0>

 [[{{node PyFunc}}]]
 [[IteratorGetNext]]
 [[IteratorGetNext/_2]]

(1) UNKNOWN: UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x7f7cad00a7f0>
Traceback (most recent call last):

File “/usr/local/lib/python3.10/dist-packages/tensorflow/python/ops/script_ops.py”, line 267, in call
ret = func(*args)

File “/usr/local/lib/python3.10/dist-packages/tensorflow/python/autograph/impl/api.py”, line 642, in wrapper
return func(*args, **kwargs)

File “/usr/local/lib/python3.10/dist-packages/tensorflow/python/data/ops/from_generator_op.py”, line 198, in generator_py_func
values = next(generator_state.get_iterator(iterator_id))

File “/usr/local/lib/python3.10/dist-packages/keras/engine/data_adapter.py”, line 902, in wrapped_generator
for data in generator_fn():

File “/usr/local/lib/python3.10/dist-packages/keras/engine/data_adapter.py”, line 1049, in generator_fn
yield x[i]

File “/usr/local/lib/python3.10/dist-packages/keras/preprocessing/image.py”, line 116, in getitem
return self._get_batches_of_transformed_samples(index_array)

File “/usr/local/lib/python3.10/dist-packages/keras/preprocessing/image.py”, line 370, in _get_batches_of_transformed_samples
img = image_utils.load_img(

File “/usr/local/lib/python3.10/dist-packages/keras/utils/image_utils.py”, line 423, in load_img
img = pil_image.open(io.BytesIO(f.read()))

File “/usr/local/lib/python3.10/dist-packages/PIL/Image.py”, line 3030, in open
raise UnidentifiedImageError(

PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x7f7cad00a7f0>

 [[{{node PyFunc}}]]
 [[IteratorGetNext]]

0 successful operations.
0 derived errors ignored. [Op:__inference_test_function_15151]

I’m not a mentor for that course, so don’t have access to the materials.

But from a python syntax perspective, you have split the model.fit(…) parameters over multiple lines. You need to be sure all the lines of code are indented correctly, even if they are inside parenthesis.

This is an example where a screen capture image would be more helpful than a text copy-and-paste.

Thank you for your response and your suggestion. The problem is rectified by ignoring the empty images during the directory creation process