Nov-02-2023, 11:45 PM
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]
[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]