# How to input different sized images into transfer learning network

I have been looking online for a solution but have a difficult time finding a clear enough solution. I want to know how to use transfer learning (VGG16 for example) on images that have different sizes than the images the network originally trained on (so instead of inputting images of size (224,224,3) I want to input images of size (32,32,3)).

I initially thought about just padding those images but the network may look into the black pixels and think that they mean something, and I realize that might hard the accuracy and also when I tried to do that my colab notebook collapsed.

This is my VGG-16 code: def vgg16_model(img_rows, img_cols, channel=1, num_classes=None):

model = VGG16(weights='imagenet', include_top=True)

model.layers.pop()

model.outputs = [model.layers[-1].output]

model.layers[-1].outbound_nodes = []

x=Dense(num_classes, activation='relu')(model.output)

model=Model(model.input,x)

#To set the first 8 layers to non-trainable (weights will not be updated)

for layer in model.layers[:15]:

layer.trainable = False
for layer in model.layers[16:]:
layer.trainable=True
model_new = Sequential()
for layer in model.layers[:-1]: # just exclude last layer from copying
model=model_new

# Learning rate is changed to 0.001
#sgd = SGD(lr=1e-2, decay=1e-6, momentum=0.9, nesterov=True)
sgd = SGD(lr=lr,decay=decay,momentum=0.95, nesterov=True)

# checkpoint
filepath="weights-improvement-{epoch:02d}-{val_acc:.2f}.hdf5"
checkpoint = ModelCheckpoint(filepath, monitor='val_acc', verbose=1, save_best_only=True, mode='max')
callbacks_list = [checkpoint]

return model


I would greatly appreciate if someone could write the corrected version of this code in order to enable me to insert pictures of size (32,32,3).

Thanks a lot in advance!!

• Have you tried upscaling images to 224*224 ? – Shamit Verma Mar 23 '19 at 16:39
• Yeah, I had a hard time finding an elegant, simple way of doing that but I ended up figuring it out, thanks! – Keren Mar 24 '19 at 19:59