W1_Using CNN's with the Cats vs Dogs Dataset_GraphExecutionError

Hi,

I was working on “Week 1: Using CNN’s with the Cats vs Dogs Dataset” assignment.
All previous tests passed except fiting the model - error shown below. I ran the whole script several times - always the same issue.

I noticed that the training V test split by me was 22500 V 2500 (the expected was 22498 V 2500)
I was wondering if I had not filtered out any “bad” files. The two zero length files had been removed in an earlier step!

Thanks for any help…


Epoch 1/15
195/352 [===============>..............] - ETA: 32s - loss: 0.6761 - accuracy: 0.4976
---------------------------------------------------------------------------
UnknownError                              Traceback (most recent call last)
<ipython-input-13-4fd84b04e1cf> in <module>
      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.8/dist-packages/tensorflow/python/eager/execute.py 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:

UnknownError: Graph execution error:

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

  File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/ops/script_ops.py", line 270, in __call__
    ret = func(*args)

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

  File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/data/ops/dataset_ops.py", line 1030, in generator_py_func
    values = next(generator_state.get_iterator(iterator_id))

  File "/usr/local/lib/python3.8/dist-packages/keras/engine/data_adapter.py", line 831, in wrapped_generator
    for data in generator_fn():

  File "/usr/local/lib/python3.8/dist-packages/keras/engine/data_adapter.py", line 957, in generator_fn
    yield x[i]

  File "/usr/local/lib/python3.8/dist-packages/keras/preprocessing/image.py", line 110, in __getitem__
    return self._get_batches_of_transformed_samples(index_array)

  File "/usr/local/lib/python3.8/dist-packages/keras/preprocessing/image.py", line 337, in _get_batches_of_transformed_samples
    img = image_utils.load_img(

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

  File "/usr/local/lib/python3.8/dist-packages/PIL/Image.py", line 2895, in open
    raise UnidentifiedImageError(

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


	 [[{{node PyFunc}}]]
	 [[IteratorGetNext]]
	 [[IteratorGetNext/_7]]
  (1) UNKNOWN:  UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x7f1566111590>
Traceback (most recent call last):

  File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/ops/script_ops.py", line 270, in __call__
    ret = func(*args)

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

  File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/data/ops/dataset_ops.py", line 1030, in generator_py_func
    values = next(generator_state.get_iterator(iterator_id))

  File "/usr/local/lib/python3.8/dist-packages/keras/engine/data_adapter.py", line 831, in wrapped_generator
    for data in generator_fn():

  File "/usr/local/lib/python3.8/dist-packages/keras/engine/data_adapter.py", line 957, in generator_fn
    yield x[i]

  File "/usr/local/lib/python3.8/dist-packages/keras/preprocessing/image.py", line 110, in __getitem__
    return self._get_batches_of_transformed_samples(index_array)

  File "/usr/local/lib/python3.8/dist-packages/keras/preprocessing/image.py", line 337, in _get_batches_of_transformed_samples
    img = image_utils.load_img(

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

  File "/usr/local/lib/python3.8/dist-packages/PIL/Image.py", line 2895, in open
    raise UnidentifiedImageError(

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


	 [[{{node PyFunc}}]]
	 [[IteratorGetNext]]
0 successful operations.
0 derived errors ignored. [Op:__inference_train_function_2516]

Hi @Mdr21,

I moved this topic to the TF1 Course 2 Week 1 Category. Please post in the right category next time. You might actually search this forum with this keyword “UnidentifiedImageError” and see if you can find some relevant discussions.

Raymond