The default input size that resnet50 takes is 224*224,so now can i change the input size of the architecture to some higher resolution and still work on it in tensorfow?
Looking at the Keras Documentation, it seems that it is possible but you will have to not include the fully-connected layer/dense layers at the top of the network.
Hi @Chaitu28 On the ResNet-50 TF Hub page it says:
m = tf.keras.Sequential([ hub.KerasLayer("https://tfhub.dev/tensorflow/resnet_50/classification/1")]) m.build([None, 224, 224, 3]) # Batch input shape.
… For this model, the size of the input images is fixed to
height
xwidth
= 224 x 224 pixels.
So, is your question about how to customize the input shape for the SavedModel of ResNet-50 on TF Hub by any chance?
Yes , is it possible?
Thank you.
@Chaitu28 , yes it is possible.
As @8bitmp3 mentioned that you have to use 224 * 224 images to directly feed the model in tfhub.
But you can use existing model for other sized images as well.
How? Let me tell you couple of ways which I can think of:
(1) Very simple solution is to resize your images (specifically I would suggest you to add padding to make square shaped and then reduce the size or center crop) to 224 * 224 and now you can feed to tfhub Resnet-50 model.
(2) More robust approach in this case would be to go for pretraining or transfer learning of a layer. Since you can see that hub.KerasLayer
defines the complete Resnet-50 as a layer and this layer is part of sequential model. So, you can define custom input size with one more Conv layer which outputs 224 * 224 * 3 image and that will solve your problem. But note here that with this new model, you need to train the model over your data which will only train the first Conv layer that we added because hub.KerasLayer
by default non-trainable (trainable
param is set to False
). See below snippet.
m = tf.keras.Sequential([
tf.keras.Input(shape=(custom_height, custom_width, 3)),
tf.keras.layers.Conv2D(....), # Define conv such that it outputs 224 * 224 * 3 images
hub.KerasLayer("https://tfhub.dev/tensorflow/resnet_50/classification/1")])
Also attaching link to doc which can help you