Python Forum
error "cannot identify image file" part way through running
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
error "cannot identify image file" part way through running
#1
I'm getting a very long list of errors part way when running the code below. The images come from: dog-vs-cat-classification/train/dogs , and the cat ones in the same folder as the dogs. Each hols 125000 images. I have plenty of RAM if related.

[It does seem to work with fewer epochs, tho not consistently]

[Sorry, tried to use the code icon but wouldn't work]

from keras.models import load_model, Sequential
from keras.layers import Conv2D,Flatten,Activation,Dense,MaxPooling2D,Dropout
from tensorflow.keras import optimizers
from tensorflow.keras.preprocessing.image import ImageDataGenerator, img_to_array
from PIL import Image
import numpy as np
import os
from sklearn.metrics import accuracy_score
from keras.preprocessing.image import ImageDataGenerator

img_width, img_height = 150, 150
trainRescale = ImageDataGenerator(rescale=1./255)

traindata = trainRescale.flow_from_directory('dog-vs-cat-classification/train', target_size = (img_width, img_height), batch_size = 32, class_mode = 'binary')

model=Sequential()

model.add(Conv2D(32,(3,3),activation='relu',input_shape=(img_width,img_height,3)))
model.add(MaxPooling2D(pool_size=(2,2)))
model.add(Conv2D(64,(3,3),activation='relu'))

model.add(MaxPooling2D(pool_size=(2,2)))
model.add(Conv2D(64,(3,3),activation='relu'))
model.add(MaxPooling2D(pool_size=(2,2)))

model.add(Flatten())
model.add(Dense(64,activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(1,activation='sigmoid'))

model.compile(loss = 'binary_crossentropy', optimizer = 'rmsprop', metrics = ['accuracy'])

model.fit_generator(traindata, steps_per_epoch = 8, epochs = 128)



Here's the output:

Epoch 1/128
8/8 [==============================] - 3s 248ms/step - loss: 0.8126 - accuracy: 0.5547
Epoch 2/128
8/8 [==============================] - 2s 233ms/step - loss: 0.6982 - accuracy: 0.4961
Epoch 3/128
8/8 [==============================] - 2s 240ms/step - loss: 0.6959 - accuracy: 0.4258
Epoch 4/128
8/8 [==============================] - 2s 238ms/step - loss: 0.6934 - accuracy: 0.5430
Epoch 5/128
6/8 [=====================>........] - ETA: 0s - loss: 0.6721 - accuracy: 0.5781C:\Users\Jim Schmitz\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\PIL\TiffImagePlugin.py:866: UserWarning: Truncated File Read
warnings.warn(str(msg))
8/8 [==============================] - 2s 231ms/step - loss: 0.6722 - accuracy: 0.5742
Epoch 6/128
8/8 [==============================] - 2s 235ms/step - loss: 0.6885 - accuracy: 0.4961
Epoch 7/128
8/8 [==============================] - 2s 234ms/step - loss: 0.7015 - accuracy: 0.5234
Epoch 8/128
3/8 [==========>...................] - ETA: 1s - loss: 0.6827 - accuracy: 0.62502023-11-02 15:11:35.715917: W tensorflow/core/framework/op_kernel.cc:1816] UNKNOWN: UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x000001BFE411ABB0>
Traceback (most recent call last):

File "C:\Users\Jim\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\tensorflow\python\ops\script_ops.py", line 268, in __call__
ret = func(*args)

and the last error line:

File "C:\Users\Jim Schmitz\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\PIL\Image.py", line 3280, in open
raise UnidentifiedImageError(msg)

PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x000001BFE411ABB0>
[[{{node PyFunc}}]]
[[IteratorGetNext]] [Op:__inference_train_function_1198]
Larz60+ write Nov-03-2023, 09:03 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Photo image error pyc0de 2 287 Mar-23-2024, 06:20 PM
Last Post: pyc0de
  identify not white pixels in bmp flash77 17 2,509 Nov-10-2023, 09:21 PM
Last Post: flash77
  Error when running kivy on python janeik 8 2,069 Jun-16-2023, 10:58 PM
Last Post: janeik
  Web project and running a .py file emont 0 652 Dec-11-2022, 11:15 PM
Last Post: emont
  is it possible to copy image from email and place into excel file? cubangt 3 1,283 Nov-30-2022, 05:11 PM
Last Post: snippsat
  New2Python: Help with Importing/Mapping Image Src to Image Code in File CluelessITguy 0 729 Nov-17-2022, 04:46 PM
Last Post: CluelessITguy
  Getting error when running "MINUS" between 2 databases marlonbown 4 1,279 Nov-10-2022, 05:49 AM
Last Post: deanhystad
  pygame image load error Yegor123 1 1,593 Oct-12-2022, 05:36 AM
Last Post: deanhystad
  Error while running code on VSC maiya 4 3,776 Jul-01-2022, 02:51 PM
Last Post: maiya
  Pandas - error when running Pycharm, but works on cmd line zxcv101 1 1,375 Jun-18-2022, 01:09 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020