I am facing the following issue when trying to train a Squeezenet with no weights and two classes:
expected loss to have shape (None, 2) but got array with shape (64, 1)
from keras.preprocessing.image import ImageDataGenerator
from keras import backend as K
from keras_squeezenet import SqueezeNet
img_width, img_height = 227, 227
train_data_dir = 'C:/IMAGES/KERAS/train'
validation_data_dir = 'C:/IMAGES/KERAS/validation'
nb_train_samples = 2000
nb_validation_samples = 800
epochs = 2
batch_size = 64
if K.image_data_format() == 'channels_first':
input_shape = (3, img_width, img_height)
else:
input_shape = (img_width, img_height, 3)
model = SqueezeNet(weights=None, classes=2)
model.compile(loss='binary_crossentropy',
optimizer='rmsprop',
metrics=['accuracy'])
train_datagen = ImageDataGenerator(
rescale=1. / 255,
shear_range=0,
zoom_range=0,
horizontal_flip=True)
test_datagen = ImageDataGenerator(rescale=1. / 255)
train_generator = train_datagen.flow_from_directory(
train_data_dir,
target_size=(img_width, img_height),
batch_size=batch_size,
class_mode='binary')
validation_generator = test_datagen.flow_from_directory(
validation_data_dir,
target_size=(img_width, img_height),
batch_size=batch_size,
class_mode='binary')
model.fit_generator(
generator=train_generator,
steps_per_epoch=nb_train_samples // batch_size,
epochs=epochs,
validation_data=validation_generator,
validation_steps=nb_validation_samples // batch_size)
Found 40294 images belonging to 2 classes.
Found 1273 images belonging to 2 classes.