segmentation_models.pytorch icon indicating copy to clipboard operation
segmentation_models.pytorch copied to clipboard

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

Open zlyin opened this issue 3 years ago • 2 comments

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'

zlyin avatar Jul 25 '22 07:07 zlyin

I have the same questions.

ZhongYupei avatar Jul 28 '22 07:07 ZhongYupei

I have the same questions.

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

zlyin avatar Jul 31 '22 13:07 zlyin

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[bot] avatar Sep 30 '22 02:09 github-actions[bot]

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

github-actions[bot] avatar Oct 08 '22 02:10 github-actions[bot]