Skip to content

Can't get attribute 'C3' on <module 'models.common' while loading yolov5s #1855

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

Closed
kaushalchapaneri-intellica opened this issue Jan 6, 2021 · 14 comments
Labels
question Further information is requested

Comments

@kaushalchapaneri-intellica
Copy link

kaushalchapaneri-intellica commented Jan 6, 2021

❔Question

I am trying to load small model of yolo v5 with following steps:

import torch

torch.load('yolov5s.pt')

but getting error AttributeError: Can't get attribute 'C3' on <module 'models.common' from '/yolov5/models/common.py'>

Additional context

i am using ubuntu 18.04
torch == 1.7.1
python = 3.8.0
please let me know if additional information is needed.

@kaushalchapaneri-intellica kaushalchapaneri-intellica added the question Further information is requested label Jan 6, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Jan 6, 2021

👋 Hello @kaushalchapaneri-intellica, 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.

@glenn-jocher
Copy link
Member

@kaushalchapaneri-intellica your code is likely out of date. You should git pull to update it or reclone the repo.

@Lnazvkl
Copy link

Lnazvkl commented Jan 13, 2021

@kaushalchapaneri-intellica your code is likely out of date. You should git pull to update it or reclone the repo.

hi, while I want to train yolov5 on custom dataset I got this error:

Traceback (most recent call last):
File "train.py", line 404, in
train(hyp)
File "train.py", line 80, in train
model = Model(opt.cfg).to(device)
File "/content/yolov5/models/yolo.py", line 57, in init
self.model, self.save = parse_model(self.md, ch=[ch]) # model, savelist, ch_out
File "/content/yolov5/models/yolo.py", line 153, in parse_model
m = eval(m) if isinstance(m, str) else m # eval strings
File "", line 1, in
NameError: name 'C3' is not defined

it happens when I use lastest yolov5x.yaml file which containes:
backbone:

[from, number, module, args]

[[-1, 1, Focus, [64, 3]], # 0-P1/2
[-1, 1, Conv, [128, 3, 2]], # 1-P2/4
[-1, 3, C3, [128]],
[-1, 1, Conv, [256, 3, 2]], # 3-P3/8
[-1, 9, C3, [256]],
[-1, 1, Conv, [512, 3, 2]], # 5-P4/16
[-1, 9, C3, [512]],
[-1, 1, Conv, [1024, 3, 2]], # 7-P5/32
[-1, 1, SPP, [1024, [5, 9, 13]]],
[-1, 3, C3, [1024, False]], # 9
]

I don't know how to solve it, I will be appreciated if you help me.

@glenn-jocher
Copy link
Member

@Lnazvkl your code is out of date. Use git pull to update your code, or simply git clone https://github.com/ultralytics/yolov5 to download a new copy.

@Lnazvkl
Copy link

Lnazvkl commented Jan 13, 2021

@Lnazvkl your code is out of date. Use git pull to update your code, or simply git clone https://github.com/ultralytics/yolov5 to download a new copy.

I had updated, but I have got this error after update.

@glenn-jocher
Copy link
Member

glenn-jocher commented Jan 13, 2021

@Lnazvkl the error you are seeing is due to out of date or modified code. To start simply clone a fresh copy of the repo, and verify training for a few epochs.

git clone https://github.com/ultralytics/yolov5
cd yolov5
python train.py --epochs 3

Alternatively you can start from the official notebook (3rd party notebooks are not supported):
https://colab.research.google.com/github/ultralytics/yolov5/blob/master/tutorial.ipynb

@glenn-jocher
Copy link
Member

glenn-jocher commented Jan 13, 2021

@Lnazvkl I will also post our full response with additional details that may help you. Please note that most technical problems are due to:

  • Your modified or out-of-date code. If your issue is not reproducible in a new git clone version of this repo we can not debug it. Before going further run this code and verify your issue persists:
$ git clone https://github.com/ultralytics/yolov5 yolov5_new  # clone latest
$ cd yolov5_new
$ python detect.py  # verify detection

# CODE TO REPRODUCE YOUR ISSUE HERE
  • Your custom data. If your issue is not reproducible in one of our 3 common datasets (COCO, COCO128, or VOC) 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 your labels and images.

  • Your environment. If your issue is not reproducible in one of the verified environments below we can not debug it. If you are running YOLOv5 locally, verify your environment meets all of the requirements.txt dependencies specified below. If in doubt, download Python 3.8.0 from https://www.python.org/, create a new venv, and install requirements.

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!

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 passing. These tests evaluate proper operation of basic YOLOv5 functionality, including training (train.py), testing (test.py), inference (detect.py) and export (export.py) on MacOS, Windows, and Ubuntu.

@Lnazvkl
Copy link

Lnazvkl commented Jan 13, 2021

@Lnazvkl I will also post our full response with additional details that may help you. Please note that most technical problems are due to:

  • Your modified or out-of-date code. If your issue is not reproducible in a new git clone version of this repo we can not debug it. Before going further run this code and verify your issue persists:
$ git clone https://github.com/ultralytics/yolov5 yolov5_new  # clone latest
$ cd yolov5_new
$ python detect.py  # verify detection

# CODE TO REPRODUCE YOUR ISSUE HERE
  • Your custom data. If your issue is not reproducible in one of our 3 common datasets (COCO, COCO128, or VOC) 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 your labels and images.
  • Your environment. If your issue is not reproducible in one of the verified environments below we can not debug it. If you are running YOLOv5 locally, verify your environment meets all of the requirements.txt dependencies specified below. If in doubt, download Python 3.8.0 from https://www.python.org/, create a new venv, and install requirements.

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!

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 passing. These tests evaluate proper operation of basic YOLOv5 functionality, including training (train.py), testing (test.py), inference (detect.py) and export (export.py) on MacOS, Windows, and Ubuntu.

as you said I update yolov5 but I got these errors:
ERROR: Could not open requirements file: [Errno 2] No such file or directory: 'requirements.txt'
python3: can't open file 'detect.py': [Errno 2] No such file or directory

image

special thanks for your attention.

@glenn-jocher
Copy link
Member

glenn-jocher commented Jan 13, 2021

@Lnazvkl I don't recognize the notebook you are using. There are many 3rd party notebooks that we do not support and that may have performance issues. I would recommend you simply start from the official YOLOv5 notebook, which is authored by Ultralytics and verified working correctly:
https://colab.research.google.com/github/ultralytics/yolov5/blob/master/tutorial.ipynb

To train with the official notebook, you simply click the Setup cell, and then run the Train cell. Two clicks gets you training correctly.
Screen Shot 2021-01-13 at 11 36 05 AM

@Lnazvkl
Copy link

Lnazvkl commented Jan 13, 2021

@Lnazvkl I don't recognize the notebook you are using. There are many 3rd party notebooks that we do not support and that may have performance issues. I would recommend you simply start from the official YOLOv5 notebook, which is authored by Ultralytics and verified working correctly:
https://colab.research.google.com/github/ultralytics/yolov5/blob/master/tutorial.ipynb

To train with the official notebook, you simply click the Setup cell, and then run the Train cell. Two clicks gets you training correctly.
Screen Shot 2021-01-13 at 11 36 05 AM

I am using google colab.

@glenn-jocher
Copy link
Member

@Lnazvkl you are using an unsupported notebook in google colab. The official Ultralytics YOLOv5 notebook is here:
https://colab.research.google.com/github/ultralytics/yolov5/blob/master/tutorial.ipynb

@Lnazvkl
Copy link

Lnazvkl commented Jan 13, 2021

@Lnazvkl you are using an unsupported notebook in google colab. The official Ultralytics YOLOv5 notebook is here:
https://colab.research.google.com/github/ultralytics/yolov5/blob/master/tutorial.ipynb

thanks for your response.

@cs-heibao
Copy link

@kaushalchapaneri-intellica
I've meet the same error(just use torch to torch.load('yolov5s.pt'))
AttributeError: Can't get attribute 'C3' on <module 'models.common' '>

@kaushalchapaneri-intellica
Copy link
Author

@cs-heibao try this:

step 1 : re clone repo in different folder by git clone https://github.com/ultralytics/yolov5.git
step 2 : cd yolov5
step 3 : then run python detect.py --source data/images/bus.jpg (assuming your python environment has all the dependencies mentioned here)

now on python terminal or in .py file run this:

import torch
torch.load('yolov5s.pt')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants