Yolov5: torch.nn.modules.module.ModuleAttributeError: 'Detect' object has no attribute 'm'

Created on 31 Jul 2020  路  15Comments  路  Source: ultralytics/yolov5

i got an error:

File "C:PythonPython38libsite-packagestorchnnmodulesmodule.py", line 722, in _call_impl
result = self.forward(input, *kwargs)
File "D:WorkGitHubyolov5modelsyolo.py", line 27, in forward
x[i] = self.mi # conv
File "C:PythonPython38libsite-packagestorchnnmodulesmodule.py", line 771, in __getattr__
raise ModuleAttributeError("'{}' object has no attribute '{}'".format(
torch.nn.modules.module.ModuleAttributeError: 'Detect' object has no attribute 'm'

question

Most helpful comment

Hey guys, I think I figured it out, please use the newly updated weights files in release V2.0 Assets instead of the old weights files, maybe there are some compatibility issues.
Specifically, please download the weights files for yolov5 V2.0 here:
https://github.com/ultralytics/yolov5/releases/tag/v2.0
and try it again.

All 15 comments

Hello @huwei1024, thank you for your interest in our work! Please visit our Custom Training Tutorial to get started, and see our Jupyter Notebook Open In Colab, Docker Image, and Google Cloud Quickstart Guide for example environments.

If this is a bug report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.

If this is a custom model or data training question, please note Ultralytics does not provide free personal support. As a leader in vision ML and AI, we do offer professional consulting, from simple expert advice up to delivery of fully customized, end-to-end production solutions for our clients, such as:

  • Cloud-based AI systems operating on hundreds of HD video streams in realtime.
  • Edge AI integrated into custom iOS and Android apps for realtime 30 FPS video inference.
  • Custom data training, hyperparameter evolution, and model exportation to any destination.

For more information please visit https://www.ultralytics.com.

@huwei1024 Hello, thank you for your interest in our work! This issue seems to lack the minimum requirements for a proper response, or is insufficiently detailed for us to help you. Please note that most technical problems are due to:

  • Your changes to the default repository. If your issue is not reproducible in a fresh git clone version of this repository we can not debug it. Before going further run this code and ensure your issue persists:
sudo rm -rf yolov5  # remove existing
git clone https://github.com/ultralytics/yolov5 && cd yolov5 # clone latest
python detect.py  # verify detection
python train.py  # verify training (a few batches only)
# CODE TO REPRODUCE YOUR ISSUE HERE
  • Your custom data. If your issue is not reproducible with COCO data we can not debug it. Visit our Custom Training Tutorial for guidelines on training your custom data. Examine train_batch0.jpg and test_batch0.jpg for a sanity check of training and testing data.
  • Your environment. If your issue is not reproducible in our Google Cloud VM or Jupyter Notebook we can not debug it. Ensure you meet the requirements specified in the README: Unix, MacOS, or Windows with Python >= 3.7, PyTorch >= 1.5 etc. You can also use our Jupyter Notebook Open In Colab and our Docker Image Docker Pulls to test your code in a working environment.

If none of these apply to you, we suggest you close this issue and raise a new one using the Bug Report template, providing screenshots and minimum viable code to reproduce your issue. Thank you!

Got the same error.
I made a new folder and git clone the yolov5 again as above,
then run:
$ python detect.py --source ./inference/images/ --weights yolov5s.pt --conf 0.4
Error shows:

Fusing layers... Model Summary: 140 layers, 7.45958e+06 parameters, 7.45958e+06 gradients
Traceback (most recent call last):
File "detect.py", line 161, in
detect()
File "detect.py", line 52, in detect
_ = model(img.half() if half else img) if device.type != 'cpu' else None # run once
File "C:UserslesAnaconda3envspytorchlibsite-packagestorchnnmodulesmodule.py", line 722, in _call_impl
result = self.forward(input, *kwargs)
File "E:202007YOLOYOLOV5yolov5modelsyolo.py", line 100, in forward
return self.forward_once(x, profile) # single-scale inference, train
File "E:202007YOLOYOLOV5yolov5modelsyolo.py", line 120, in forward_once
x = m(x) # run
File "C:UserslesAnaconda3envspytorchlibsite-packagestorchnnmodulesmodule.py", line 722, in _call_impl
result = self.forward(input, *kwargs)
File "E:202007YOLOYOLOV5yolov5modelsyolo.py", line 27, in forward
x[i] = self.mi # conv
File "C:UserslesAnaconda3envspytorchlibsite-packagestorchnnmodulesmodule.py", line 772, in __getattr__
type(self).__name__, name))
torch.nn.modules.module.ModuleAttributeError: 'Detect' object has no attribute 'm'

My enviroment is windows 10, anaconda 4.8.3, pytorch 1.6+cuda 10.1 and yolov5 V2.0 release

@huwei1024 @infooptwang make sure both your both and models are up to date. If in doubt, simply start from a clean slate: reclone the repo (do not copy any older models), and run the same command. CI tests are passing on all OS's, so all basic functionality is currently operating correctly.

I have the same problem, my code shows this error torch.nn.modules.module.ModuleAttributeError: 'Detect' object has no attribute 'm' I run the detect function and detect the example images.

I try to run a .pt file and this is my error.

is there a problem if the .pt file is compressed vs binary?

@glenn-jocher I appreciate if you can help me!

Hey guys, I think I figured it out, please use the newly updated weights files in release V2.0 Assets instead of the old weights files, maybe there are some compatibility issues.
Specifically, please download the weights files for yolov5 V2.0 here:
https://github.com/ultralytics/yolov5/releases/tag/v2.0
and try it again.

i am running test.py after training the model facing similar issue.However while running train.py or detect.py it was running successfully. Later after break of 1-2 days when i thought checking the performance facing this issue
Using - recent repo and google colab notebook

Following error shows up for test.py:
File "test.py", line 265, in
opt.verbose)
File "test.py", line 42, in test
model = attempt_load(weights, map_location=device) # load FP32 model
File "/content/gdrive/My Drive/t2/yolov5/models/experimental.py", line 133, in attempt_load
model.append(torch.load(w, map_location=map_location)['model'].float().fuse().eval()) # load FP32 model
File "/content/gdrive/My Drive/t2/yolov5/models/yolo.py", line 151, in fuse
m.conv = torch_utils.fuse_conv_and_bn(m.conv, m.bn) # update conv
File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 802, in __setattr__
remove_from(self.__dict__, self._parameters, self._buffers, self._non_persistent_buffers_set)
File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 772, in __getattr__
type(self).__name__, name))
torch.nn.modules.module.ModuleAttributeError: 'Conv' object has no attribute '_non_persistent_buffers_set'

@sumanttyagi and anyone else having this issue:

Ensure both your code and models are up to date. If in doubt, simply start from a clean slate: reclone the repo (do not copy any older models, the latest models are autodownloaded as required), and run the same commands. CI tests are passing on all OS's, so all basic functionality (train, test, detect) is currently operating correctly across Linux, MacOS and Windows.

_File "detect.py", line 171, in
detect()
File "detect.py", line 72, in detect
pred = model(img, augment=opt.augment)[0]
File "E:yolov5venvlibsite-packagestorchnnmodulesmodule.py", line 722, in _call_impl
result = self.forward(input, *kwargs)
File "E:yolov5modelsyolo.py", line 109, in forward
return self.forward_once(x, profile) # single-scale inference, train
File "E:yolov5modelsyolo.py", line 129, in forward_once
x = m(x) # run
File "E:yolov5venvlibsite-packagestorchnnmodulesmodule.py", line 722, in _call_impl
result = self.forward(input, *kwargs)
File "E:yolov5modelsyolo.py", line 34, in forward
self.training |= self.export
File "E:yolov5venvlibsite-packagestorchnnmodulesmodule.py", line 772, in __getattr__
type(self).__name__, name))
torch.nn.modules.module.ModuleAttributeError: 'Detect' object has no attribute 'export'_

Got Same Error. Working Well When I am using old weights. But when using new weights (freshly trained weights for new classes) this error is coming up

@navalsheth cause is older code or models. Start from a clean slate with the latest git clone, let autodownload pull any models it wants (don't manually download pretrained weights) and you're all set.

@glenn-jocher - thanks glenn, it worked making starting from scratch. (Though did download pre trained weights manually).

@glenn-jocher - Good input of not downloading manually.How can we pull pretrained weights in my google colab(which i trained) to local in that case(Windows 10)

@navalsheth any command you make requesting pretrained weights will autodownload the latest weights if not found locally. This works in colab or any other environment with internet access.

You can find previous versions of the weights attached to each release:
https://github.com/ultralytics/yolov5/releases

Was this page helpful?
0 / 5 - 0 ratings

Related issues

FSNStefan picture FSNStefan  路  4Comments

hktxt picture hktxt  路  3Comments

xinxin342 picture xinxin342  路  3Comments

lisa676 picture lisa676  路  3Comments

dereyly picture dereyly  路  4Comments