Feature extraction using EfficeintNet

I have seen multiple feature extraction network Alexnet, ResNet. And it is quite easy to extract features from specific module for all these networks using
resnet1 = models.resnet50(pretrained=True)
modules1 = list(resnet1.children())[:-1]

But in case of Effcientnet if you use the this command. Just at difference of 1, whole model is gone
See the output of these two
eff1 = EfficientNet.from_pretrained(‘efficientnet-b0’)
modules1 = list(eff1.children())[:-6]
modules1 = nn.Sequential(*modules1)
print(modules1)

resnet1 = EfficientNet.from_pretrained(‘efficientnet-b0’)
modules1 = list(eff1.children())[0:-7]
modules1 = nn.Sequential(*modules1)
print(modules1)

The whole network of MB Blocks is gone.
Considering Table 1 in main paper EfficientNet
If i want to extract output of stage 5 from pretrained model and want to combine with mine separate CNN network for further classification(self.conv1, self.fc1, self.fc2,num_classes=10).
How I can use that?

Base on your code, i think you are using this implementation of EfficientNet
check this link for the source code and more information.
you can use extract_endpoints or extract_features.

Dictionary of last intermediate features
with reduction levels i in [1, 2, 3, 4, 5].
Example:

import torch
from efficientnet.model import EfficientNet
inputs = torch.rand(1, 3, 224, 224)
model = EfficientNet.from_pretrained(‘efficientnet-b0’)
endpoints = model.extract_endpoints(inputs)
print(endpoints[‘reduction_1’].shape) # torch.Size([1, 16, 112, 112])
print(endpoints[‘reduction_2’].shape) # torch.Size([1, 24, 56, 56])
print(endpoints[‘reduction_3’].shape) # torch.Size([1, 40, 28, 28])
print(endpoints[‘reduction_4’].shape) # torch.Size([1, 112, 14, 14])
print(endpoints[‘reduction_5’].shape) # torch.Size([1, 320, 7, 7])
print(endpoints[‘reduction_6’].shape) # torch.Size([1, 1280, 7,

1 Like