Yolov5: No module named 'models' question

Created on 19 Jun 2020  路  9Comments  路  Source: ultralytics/yolov5

馃悰 Bug

When I use yolov5 outside the repo and use "torch.load(the_mode, PATH)", I got the error "No module named 'models'"

I see a solution in #22.

But I got error when I use model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True)

torch.nn.modules.module.ModuleAttributeError: 'BatchNorm2d' object has no attribute '_non_persistent_buffers_set'

So I still want to load model in this way:
model.load_state_dict(torch.load(new_weights))
Can you tell me how to use model.load_state_dict ?

bug

Most helpful comment

I have the same problem, torch 1.6rc2
File "detect.py", line 23, in detect
model = attempt_load(weights, map_location=device) # load FP32 model
File "/home/ruichen/nvme/gitrepo/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 "/home/ruichen/nvme/gitrepo/yolov5/models/yolo.py", line 149, 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'

All 9 comments

Hello @ioir123ju, 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 that 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.

@ioir123ju use Torch Hub. See https://github.com/ultralytics/yolov5/issues/36

Screen Shot 2020-06-18 at 7 01 46 PM

Sorry, It doesn't solve my problem.
image

environment

pytorch 1.6

@ioir123ju use a working environment. See https://github.com/ultralytics/yolov5#reproduce-our-environment

yes, My environment meets your requirements.

torch 1.6 >= torch1.5
python 3.7

And I can run detect.py in your repo.
But can't load weight in my project.

@ioir123ju debug your environment, or just use one of our working ones. That's what they are there for.

I have the same problem, torch 1.6rc2
File "detect.py", line 23, in detect
model = attempt_load(weights, map_location=device) # load FP32 model
File "/home/ruichen/nvme/gitrepo/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 "/home/ruichen/nvme/gitrepo/yolov5/models/yolo.py", line 149, 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'

Same problem over here.

@fpingham you are probably using an older version of the repo, an older model, or are not meeting the minimum dependency requirements. I would start from a clean slate in one of the verified environments below.

Environments

YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hktxt picture hktxt  路  3Comments

dereyly picture dereyly  路  4Comments

maykulkarni picture maykulkarni  路  3Comments

lisa676 picture lisa676  路  3Comments

KangHoyong picture KangHoyong  路  3Comments