Reputation: 2670
For transfer learning I am using ResNet50 as a feature extractor. By making top = False I am taking the output from the layer which is just before the last layer. The output should have a size of (#examples, 7, 7, 2048)
as documentation of ResNet50. But I faced an strange issue. I am getting the output shape of (#examples, 8, 8, 2048)
. Following is the code:
model = ResNet50(weights="imagenet", include_top=False)
# batchImages is a list containing images in that batch
# bs is the batch size
features = model.predict(batchImages, batch_size = bs)
Here the shape of the feature should be (#examples, 7, 7, 2048)
but it is giving (#examples, 8, 8, 2048)
. Why this is happening?
Upvotes: 0
Views: 1040
Reputation: 36
This is absolutely normal, the size reduction in ResNet is given by the MaxPooling of size 2x2 after each block. Since there are 5 blocks in Resnet, you will always get input_size / 2**5. 224 / 32 = 7 256 / 32 = 8
Upvotes: 2
Reputation: 2670
As I have found the output feature size in ResNet50 (with top = False) depends on the input shape of the images. Although in documentations I found that the output feature shape in this cases would be (#examples, 7, 7, 2048)
but it changes when I change the input image shape. Although I didn't find any clarification on this anywhere. But as I have seen whenever I am using images of size (224 x 224)
it is working completely okay. But when I increase the input image's size to (255 x 255)
the output feature vector size changes to (#examples, 8, 8, 2048)
. This looks weird but actually this is happening.
Upvotes: 0