Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EfficientNet without Top Layers #192

Closed
nhorangl opened this issue Jun 10, 2020 · 5 comments
Closed

EfficientNet without Top Layers #192

nhorangl opened this issue Jun 10, 2020 · 5 comments

Comments

@nhorangl
Copy link

I tried to remove top layers like follows:

base_model = EfficientNet.from_pretrained('efficientnet-b3')
model = nn.Sequential(*list(base_model.children()[:-3]))

x = torch.randn((1,3,300,300))
model(x)

It throws "NotImplementedError" for forward(). Is there a way to not include top layers?

@Cyril9227
Copy link

Overwrite the forward method to yield the features map of the desired layer

@nwschurink
Copy link

Yes, or add an option to the initialization of the network that allows dropping these layers (similar to how EfficientNet is implemented in Tensorflow).
I made the adjustments for a EfficientNet3D fork of this repo -> see pull request here shijianjian#4
If you want I can also change the code for this repo and post a pull request here

@23pointsNorth
Copy link

@nwschurink 's solution is much better, but in the mean time, an alternative is to substitute them with Identity layers:

model._fc = nn.Identity()
model._swish = nn.Identity()

lukemelas added a commit that referenced this issue Aug 25, 2020
@lukemelas
Copy link
Owner

This is now integrated :)

@23pointsNorth
Copy link

@lukemelas is it going to be in the next pip version? Or do you know when it's planned for release?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants