Cannot achieve good result while Transfer Learning CIFAR-10 on ResNet50 - Keras
I'm trying to Transfer Learn ResNet50 for image classification of the CIFAR-10 dataset.
It's stated in the original paper and also ResNet50 documentation on keras.io that the ResNet should have a minimum input shape of 32x32. But I cannot achieve any good results.
Here I have created and compiled the sequential model:
model = Sequential()
model.add(ResNet50(include_top=False, weights='imagenet', input_shape=(32,32,3)))
model.add(Flatten())
model.add(BatchNormalization())
model.add(Dense(128, activation='relu')) #Dense Layer
model.add(Dropout(0.5)) #Dropout
model.add(Dense(10, activation='softmax')) #Output Layer
model.layers[0].trainable = False #Set ResNet as NOT trainable
model.summary()
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
and here I have loaded the CIFAR-10 dataset:
(x_train, y_train), (x_test, y_test) = cifar10.load_data() #Load dataset
num_classes = len(np.unique(y_test))
(x_train, x_valid) = x_train[5000:],x_train[:5000] #set 5000 validation data
(y_train, y_valid) = y_train[5000:],y_train[:5000]
y_train = to_categorical(y_train,num_classes) #Convert to one-hot
y_test = to_categorical(y_test,num_classes)
y_valid = to_categorical(y_valid,num_classes)
Note that on the keras.io website documentation for the resnet50.preprocess_input, it is stated that the input data has 0-255 range. So then to preprocess data I used:
x_train = preprocess_input(x_train.copy()) #preprocess training images for the resnet50
x_test = preprocess_input(x_test.copy()) #preprocess test images for the resnet50
x_valid = preprocess_input(x_valid.copy()) #preprocess validation images for the resnet50
And here's the fitting section:
ModelHistory = model.fit(x_train, y_train,
batch_size=32,
epochs=10, verbose=0,
validation_data=(x_valid,y_valid),
callbacks=[earlystop]) #Use Early Stopping
But the result I get is terrible even after ~20 epochs (~67% testing accuracy)
Where am I doing wrong?
Topic transfer-learning keras tensorflow classification
Category Data Science