av-savchenko / face-emotion-recognition

Efficient face emotion recognition in photos and videos
Apache License 2.0
687 stars 127 forks source link

AttributeError: 'SqueezeExcite' object has no attribute 'gate' #12

Closed evercy closed 2 years ago

evercy commented 2 years ago

Excuse me, this problem occurs when using the ‘enet_b2_7.pt’ model to test. I completed it according to the steps you gave, but I really couldn't find the reason for this problem. Do you have any suggestions?

evercy commented 2 years ago

Here is the detailed error message.

/usr/local/lib/python3.7/dist-packages/ipykernel_launcher.py:13: DeprecationWarning: np.int is a deprecated alias for the builtin int. To silence this warning, use int by itself. Doing this will not modify any behavior and is safe. When replacing np.int, you may wish to use e.g. np.int64 or np.int32 to specify the precision. If you wish to review your current use, check the release note link for additional information. Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations del sys.path[0]

AttributeError Traceback (most recent call last) in () 17 img_tensor = test_transforms(Image.fromarray(face_img)) 18 imgtensor.unsqueeze(0) ---> 19 scores = model(img_tensor.to(device)) 20 scores=scores[0].data.cpu().numpy() 21 plt.figure(figsize=(3, 3))

11 frames /usr/local/lib/python3.7/dist-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 = [], []

/usr/local/lib/python3.7/dist-packages/timm/models/efficientnet.py in forward(self, x) 518 519 def forward(self, x): --> 520 x = self.forward_features(x) 521 x = self.global_pool(x) 522 if self.drop_rate > 0.:

/usr/local/lib/python3.7/dist-packages/timm/models/efficientnet.py in forward_features(self, x) 511 x = self.bn1(x) 512 x = self.act1(x) --> 513 x = self.blocks(x) 514 x = self.conv_head(x) 515 x = self.bn2(x)

/usr/local/lib/python3.7/dist-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 = [], []

/usr/local/lib/python3.7/dist-packages/torch/nn/modules/container.py in forward(self, input) 139 def forward(self, input): 140 for module in self: --> 141 input = module(input) 142 return input 143

/usr/local/lib/python3.7/dist-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 = [], []

/usr/local/lib/python3.7/dist-packages/torch/nn/modules/container.py in forward(self, input) 139 def forward(self, input): 140 for module in self: --> 141 input = module(input) 142 return input 143

/usr/local/lib/python3.7/dist-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 = [], []

/usr/local/lib/python3.7/dist-packages/timm/models/efficientnet_blocks.py in forward(self, x) 120 x = self.act1(x) 121 --> 122 x = self.se(x) 123 124 x = self.conv_pw(x)

/usr/local/lib/python3.7/dist-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 = [], []

/usr/local/lib/python3.7/dist-packages/timm/models/efficientnet_blocks.py in forward(self, x) 45 x_se = self.act1(x_se) 46 x_se = self.conv_expand(x_se) ---> 47 return x * self.gate(x_se) 48 49

/usr/local/lib/python3.7/dist-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: 'SqueezeExcite' object has no attribute 'gate'

av-savchenko commented 2 years ago

Please, check that you have the timm package version 0.4.5 (see readme). They changed EfficientNet in the latest package after I trained my models

evercy commented 2 years ago

Thanks for your help, it is now up and running, thanks for the excellent work you did.

av-savchenko commented 2 years ago

Ok, nice, I'm closing the issue