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 ?
Hello @ioir123ju, thank you for your interest in our work! Please visit our Custom Training Tutorial to get started, and see our Jupyter Notebook , 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:
For more information please visit https://www.ultralytics.com.
@ioir123ju use Torch Hub. See https://github.com/ultralytics/yolov5/issues/36

Sorry, It doesn't solve my problem.

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.
YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):
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'