I tried a binary classification using CNN. Done with the exact same code as explained on https://www.udemy.com/deeplearning/. But when I run the code on my PC(CPU- 8 GB RAM) , the training executes very slowly with a single item in each epoch ,even though I have given the batch size as 32. However, it runs just as fine on the instructor's computer(even though he too is using CPU). The train set consists of a total of 8000 images and the test set with 2000 images. I know for such large data, the processing will definitely will be slow, but I am noticing it is much slower than usual.
from keras.layers import Dense
from keras.layers import Convolution2D
from keras.layers import MaxPooling2D
from keras.layers import Flatten
from keras.models import Sequential
classifier=Sequential()
classifier.add(Convolution2D(32, (3, 3 ), input_shape=(64,64,3),activation='relu'))
classifier.add(MaxPooling2D(pool_size=(2 , 2)))
classifier.add(Flatten())
classifier.add(Dense(units=128, activation='relu'))
classifier.add(Dense(units=1, activation='sigmoid'))
classifier.compile(optimizer='adam' , loss='binary_crossentropy' ,metrics=['accuracy'])
from keras.preprocessing.image import ImageDataGenerator
train_datagen = ImageDataGenerator(
rescale=1./255,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True)
test_datagen = ImageDataGenerator(rescale=1./255)
training_set = train_datagen.flow_from_directory(
'dataset/training_set',
target_size=(64, 64), #since 64,64,pixels
batch_size=32,
class_mode='binary')
test_set= test_datagen.flow_from_directory(
'dataset/test_set',
target_size=(64, 64),
batch_size=32,
class_mode='binary')
classifier.fit_generator(
training_set,
steps_per_epoch=8000,
epochs=25,
validation_data=test_set,
validation_steps=2000)
The flow from directory based image preprocessing is done as explained in the Keras documentation, With Tensorflow as a backend.
Thanks!