Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I am a student of Tsinghua University, doing research in Tencent. When I train with yolov5, the following problems appear,Sincerely hope to get help, #2203

Closed
xianglei3 opened this issue Feb 13, 2021 · 4 comments
Labels
bug Something isn't working Stale Stale and schedule for closing soon

Comments

@xianglei3
Copy link

xianglei3 commented Feb 13, 2021

My environment was win10 Python 3.7 Pytorch 1.7
I use the yolov5s model
I use the latest version of 2021.2.13 official websitend the data set voc2014
My CUDA was version 10.2

When I run Python train.py , The error is as follows
RuntimeError: ZeroDivisionError
File "E:/yoloV5/yolov5-master/train.py", line 83, in train
model = Model(opt.cfg or ckpt['model'].yaml, ch=3, nc=nc).to(device) # create
File "C:\Users\asus\anaconda3\envs\test\lib\site-packages\torch\nn\modules\module.py", line 778, in getattr
raise ModuleAttributeError("'{}' object has no attribute '{}'".format(
torch.nn.modules.module.ModuleAttributeError: 'Model' object has no attribute 'yaml'

The error comes from the following code:
ckpt = torch.load(weights, map_location=device) # load checkpoint
if hyp.get('anchors'):
ckpt['model'].yaml['anchors'] = round(hyp['anchors']) # force autoanchor
model = Model(opt.cfg or ckpt['model'].yaml, ch=3, nc=nc).to(device) # create

The key question is “Model' object has no attribute 'yaml'”

I found two important clue :
first :
I found that “opt.cfg” was empty and could not print anything, the key codes are as follows
print (opt.cfg)
model = Model(opt.cfg or ckpt['model'].yaml, ch=3, nc=nc).to(device) # create

second:
In the following code, the program runs the else branch,so ckpt['model'].yaml is not properly initialized or initialized,the key codes are as follows
if pretrained:
with torch_distributed_zero_first(rank):
attempt_download(weights) # download if not found locally
ckpt = torch.load(weights, map_location=device) # load checkpoint
if hyp.get('anchors'):
ckpt['model'].yaml['anchors'] = round(hyp['anchors']) # force autoanchor

To sum up, when I was training, the error of the console printing was:
model = Model(opt.cfg or ckpt['model'].yaml, ch=3, nc=nc).to(device) # create
File "C:\Users\asus\anaconda3\envs\test\lib\site-packages\torch\nn\modules\module.py", line 778, in getattr
raise ModuleAttributeError("'{}' object has no attribute '{}'".format(
torch.nn.modules.module.ModuleAttributeError: 'Model' object has no attribute 'yaml'

I look forward to your help. Thank you very much. Thank you forever

@xianglei3 xianglei3 added the bug Something isn't working label Feb 13, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Feb 13, 2021

👋 Hello @xianglei3, thank you for your interest in 🚀 YOLOv5! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution.

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 training ❓ Question, please provide as much information as possible, including dataset images, training logs, screenshots, and a public link to online W&B logging if available.

For business inquiries or professional support requests please visit https://www.ultralytics.com or email Glenn Jocher at glenn.jocher@ultralytics.com.

Requirements

Python 3.8 or later with all requirements.txt dependencies installed, including torch>=1.7. To install run:

$ pip install -r requirements.txt

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):

Status

CI CPU testing

If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training (train.py), testing (test.py), inference (detect.py) and export (export.py) on MacOS, Windows, and Ubuntu every 24 hours and on every commit.

@xianglei3
Copy link
Author

the code is
if pretrained:
with torch_distributed_zero_first(rank):
attempt_download(weights) # download if not found locally
ckpt = torch.load(weights, map_location=device) # load checkpoint
if hyp.get('anchors'):
ckpt['model'].yaml['anchors'] = round(hyp['anchors']) # force autoanchor

@glenn-jocher
Copy link
Member

glenn-jocher commented Feb 13, 2021

@xianglei3 VOC trains very well with YOLOv5, >0.90 mAP. You may be using an older or corrupted model. YOLOv5 will auto-download new models on demand the first time you request them, so I would simply start from scratch with a new git clone, and follow the VOC training commands shown in the Colab Notebook (Appendix section):
https://colab.research.google.com/github/ultralytics/yolov5/blob/master/tutorial.ipynb

# VOC
for b, m in zip([64, 48, 32, 16], ['yolov5s', 'yolov5m', 'yolov5l', 'yolov5x']):  # zip(batch_size, model)
  !python train.py --batch {b} --weights {m}.pt --data voc.yaml --epochs 50 --cache --img 512 --nosave --hyp hyp.finetune.yaml --project VOC --name {m}

If you just want to train say YOLOv5m on VOC, you can run this command, no need to download VOC or download any pretrained weights, it's all done automatically:

python train.py --batch 48 --weights yolov5m.pt --data voc.yaml --epochs 50 --cache --img 512 --nosave --hyp hyp.finetune.yaml --project VOC --name yolov5m

@github-actions
Copy link
Contributor

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the Stale Stale and schedule for closing soon label Mar 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Stale Stale and schedule for closing soon
Projects
None yet
Development

No branches or pull requests

2 participants