Skip to content

'EfficientNetEncoder' object has no attribute 'act1' when loading back timm-efficient-b5 weights #618

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

Closed
zlyin opened this issue Jul 25, 2022 · 4 comments
Labels

Comments

@zlyin
Copy link

zlyin commented Jul 25, 2022

I trained a model of timm-efficientnet-b5 with imagenet pretrained weights on my custom dataset. The train & val process works good. Then when I loaded it back in another script & inferred on a batch of images, it threw out the error AttributeError: 'EfficientNetEncoder' object has no attribute 'act1', as follows. Any idea about this wired issue?

Thank you very much!

/tmp/ipykernel_33/3205381621.py in __iter__(self)
     20                     # infer with each model
     21                     for model in self.models:
---> 22                         p = model(x)
     23                         p = torch.sigmoid(p).detach()
     24                         if py is None:

/opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
   1108         if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks
   1109                 or _global_forward_hooks or _global_forward_pre_hooks):
-> 1110             return forward_call(*input, **kwargs)
   1111         # Do not call functions when jit is used
   1112         full_backward_hooks, non_full_backward_hooks = [], []

/kaggle/input/segmentation-models-pytorch/segmentation_models.pytorch-0.2.1/segmentation_models_pytorch/base/model.py in forward(self, x)
     13     def forward(self, x):
     14         """Sequentially pass `x` trough model`s encoder, decoder and heads"""
---> 15         features = self.encoder(x)
     16         decoder_output = self.decoder(*features)
     17 

/opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
   1108         if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks
   1109                 or _global_forward_hooks or _global_forward_pre_hooks):
-> 1110             return forward_call(*input, **kwargs)
   1111         # Do not call functions when jit is used
   1112         full_backward_hooks, non_full_backward_hooks = [], []

/kaggle/input/segmentation-models-pytorch/segmentation_models.pytorch-0.2.1/segmentation_models_pytorch/encoders/timm_efficientnet.py in forward(self, x)
    113 
    114     def forward(self, x):
--> 115         stages = self.get_stages()
    116 
    117         features = []

/kaggle/input/segmentation-models-pytorch/segmentation_models.pytorch-0.2.1/segmentation_models_pytorch/encoders/timm_efficientnet.py in get_stages(self)
    105         return [
    106             nn.Identity(),
--> 107             nn.Sequential(self.conv_stem, self.bn1, self.act1),
    108             self.blocks[:self._stage_idxs[0]],
    109             self.blocks[self._stage_idxs[0]:self._stage_idxs[1]],

/opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py in __getattr__(self, name)
   1184                 return modules[name]
   1185         raise AttributeError("'{}' object has no attribute '{}'".format(
-> 1186             type(self).__name__, name))
   1187 
   1188     def __setattr__(self, name: str, value: Union[Tensor, 'Module']) -> None:

AttributeError: 'EfficientNetEncoder' object has no attribute 'act1'
@ZhongYupei
Copy link

I have the same questions.

@zlyin
Copy link
Author

zlyin commented Jul 31, 2022

I have the same questions.

I found out the reason, you have to downgrade timm to 5.+

@github-actions
Copy link

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale label Sep 30, 2022
@github-actions
Copy link

github-actions bot commented Oct 8, 2022

This issue was closed because it has been stalled for 7 days with no activity.

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

No branches or pull requests

2 participants