'InvalidArgumentError: Graph execution error:

Could someone please help me with this error

Here is the error I am getting when trying to train my model, I'm still pretty new to python

Here is my model

It wouldn't even get past the first epoch I am trying to create an object detection model using two classes "completed" and "missing" I created subfolders for the classes and initially started with the images in a hcei format which I changed to png using a code and possibly that's where the error is coming from because I think the error is due to a corrupt image in my dataset but maybe it could also be that it's not able to read each image due to how I set the 'data generator function' up Below is the full error I am getting

 Epoch 1/10
 3/31 [=>............................] - ETA: 5:30 - loss: 2.0630 - accuracy: 0.36672022-02-23 04:57:25.752716: W tensorflow/core/framework/op_kernel.cc:1733] UNKNOWN: UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x7f8b3229ebd0>
Traceback (most recent call last):

  File "/Users/emmanuelakinwale/opt/anaconda3/envs/playground/lib/python3.9/site-packages/tensorflow/python/ops/script_ops.py", line 271, in __call__
    ret = func(*args)

  File "/Users/emmanuelakinwale/opt/anaconda3/envs/playground/lib/python3.9/site-packages/tensorflow/python/autograph/impl/api.py", line 642, in wrapper
    return func(*args, **kwargs)

  File "/Users/emmanuelakinwale/opt/anaconda3/envs/playground/lib/python3.9/site-packages/tensorflow/python/data/ops/dataset_ops.py", line 1004, in generator_py_func
    values = next(generator_state.get_iterator(iterator_id))

  File "/Users/emmanuelakinwale/opt/anaconda3/envs/playground/lib/python3.9/site-packages/keras/engine/data_adapter.py", line 830, in wrapped_generator
    for data in generator_fn():

  File "/Users/emmanuelakinwale/opt/anaconda3/envs/playground/lib/python3.9/site-packages/keras/engine/data_adapter.py", line 956, in generator_fn
    yield x[i]

  File "/Users/emmanuelakinwale/opt/anaconda3/envs/playground/lib/python3.9/site-packages/keras_preprocessing/image/iterator.py", line 65, in __getitem__
    return self._get_batches_of_transformed_samples(index_array)

  File "/Users/emmanuelakinwale/opt/anaconda3/envs/playground/lib/python3.9/site-packages/keras_preprocessing/image/iterator.py", line 227, in _get_batches_of_transformed_samples
    img = load_img(filepaths[j],

  File "/Users/emmanuelakinwale/opt/anaconda3/envs/playground/lib/python3.9/site-packages/keras_preprocessing/image/utils.py", line 114, in load_img
    img = pil_image.open(io.BytesIO(f.read()))

  File "/Users/emmanuelakinwale/.local/lib/python3.9/site-packages/PIL/Image.py", line 3008, in open
    raise UnidentifiedImageError(

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


---------------------------------------------------------------------------
UnknownError                              Traceback (most recent call last)
Input In [22], in <module>
      1 #Training and validation
----> 2 cnn.fit(x = training_set, validation_data = test_set, epochs = 10)

File ~/opt/anaconda3/envs/playground/lib/python3.9/site-packages/keras/utils/traceback_utils.py:67, in filter_traceback.<locals>.error_handler(*args, **kwargs)
     65 except Exception as e:  # pylint: disable=broad-except
     66   filtered_tb = _process_traceback_frames(e.__traceback__)
---> 67   raise e.with_traceback(filtered_tb) from None
     68 finally:
     69   del filtered_tb

File ~/opt/anaconda3/envs/playground/lib/python3.9/site-packages/tensorflow/python/eager/execute.py:54, in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name)
     52 try:
     53   ctx.ensure_initialized()
---> 54   tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
     55                                       inputs, attrs, num_outputs)
     56 except core._NotOkStatusException as e:
     57   if name is not None:

UnknownError: Graph execution error:

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

  File "/Users/emmanuelakinwale/opt/anaconda3/envs/playground/lib/python3.9/site-packages/tensorflow/python/ops/script_ops.py", line 271, in __call__
    ret = func(*args)

  File "/Users/emmanuelakinwale/opt/anaconda3/envs/playground/lib/python3.9/site-packages/tensorflow/python/autograph/impl/api.py", line 642, in wrapper
    return func(*args, **kwargs)

  File "/Users/emmanuelakinwale/opt/anaconda3/envs/playground/lib/python3.9/site-packages/tensorflow/python/data/ops/dataset_ops.py", line 1004, in generator_py_func
    values = next(generator_state.get_iterator(iterator_id))

  File "/Users/emmanuelakinwale/opt/anaconda3/envs/playground/lib/python3.9/site-packages/keras/engine/data_adapter.py", line 830, in wrapped_generator
    for data in generator_fn():

  File "/Users/emmanuelakinwale/opt/anaconda3/envs/playground/lib/python3.9/site-packages/keras/engine/data_adapter.py", line 956, in generator_fn
    yield x[i]

  File "/Users/emmanuelakinwale/opt/anaconda3/envs/playground/lib/python3.9/site-packages/keras_preprocessing/image/iterator.py", line 65, in __getitem__
    return self._get_batches_of_transformed_samples(index_array)

  File "/Users/emmanuelakinwale/opt/anaconda3/envs/playground/lib/python3.9/site-packages/keras_preprocessing/image/iterator.py", line 227, in _get_batches_of_transformed_samples
    img = load_img(filepaths[j],

  File "/Users/emmanuelakinwale/opt/anaconda3/envs/playground/lib/python3.9/site-packages/keras_preprocessing/image/utils.py", line 114, in load_img
    img = pil_image.open(io.BytesIO(f.read()))

  File "/Users/emmanuelakinwale/.local/lib/python3.9/site-packages/PIL/Image.py", line 3008, in open
    raise UnidentifiedImageError(

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


     [[{{node PyFunc}}]]
     [[IteratorGetNext]] [Op:__inference_train_function_1879]


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source