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(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.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,
                         epochs=10, verbose=0,
                         callbacks=[earlystop])                     #Use Early Stopping

But the result I get is terrible even after ~20 epochs (~67% testing accuracy)

Where am I doing wrong?


1 Answer 1


I was able to achieve better results by upsampling the input images (using UpSample2D((6,6))) Accuracy of ~82% was achieved. For better results, I think one could upsample more, or add another Dense layer at the output.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.