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

Fails when instantiation of YOLO (model = YOLO("path/yolov5l.yaml")) #12640

Closed
1 of 2 tasks
JDang-At-Festo opened this issue Jan 16, 2024 · 4 comments
Closed
1 of 2 tasks
Labels
bug Something isn't working

Comments

@JDang-At-Festo
Copy link

Search before asking

  • I have searched the YOLOv5 issues and found no similar bug report.

YOLOv5 Component

Other

Bug

Basic problem description

Hello, so I am trying to train a model from scratch using the yaml files given with the repo from Ultralytics. Looking at their python training examples documentation. However the code gets hung up on the instantiation of the YOLO object itself. I get an 'init' error. This branches from the 'tasks.py' file included in the ultralytics pip installation. On line 718:

m_ = nn.Sequential(*(m(*args) for _ in range(n))) if n > 1 else m(*args)  # module

Now this is able to traverse through all of the layers except layer 23. Below I will include the yaml file.
Once I hit layer 23 I get this error message:

Detect.init() takes from 1 to 3 positional arguments but 4 were given
File "C:\Appl\Python\Lib\site-packages\ultralytics\nn\tasks.py", line 718, in parse_model
m_ = nn.Sequential(*(m(*args) for _ in range(n))) if n > 1 else m(*args) # module
File "C:\Appl\Python\Lib\site-packages\ultralytics\nn\tasks.py", line 232, in init
self.model, self.save = parse_model(deepcopy(self.yaml), ch=ch, verbose=verbose) # model, savelist
File "C:\Appl\Python\Lib\site-packages\ultralytics\engine\model.py", line 128, in _new
self.model = (model or self._smart_load('model'))(cfg_dict, verbose=verbose and RANK == -1) # build model
File "C:\Appl\Python\Lib\site-packages\ultralytics\engine\model.py", line 92, in init
self._new(model, task)
File "C:\Users\us0jsdn\Desktop\Workspaces\Python\Sandbox\yolov5\Pipelines\TrainFromScratch.py", line 9, in
model_L = YOLO('./yolov5/Pipelines/models/yolov5l.yaml')
File "C:\Appl\Python\Lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "C:\Appl\Python\Lib\runpy.py", line 196, in _run_module_as_main (Current frame)
return _run_code(code, main_globals, None,
TypeError: Detect.init() takes from 1 to 3 positional arguments but 4 were given

Call stack

parse_model (c:\Appl\Python\Lib\site-packages\ultralytics\nn\tasks.py:718)
init (c:\Appl\Python\Lib\site-packages\ultralytics\nn\tasks.py:232)
_new (c:\Appl\Python\Lib\site-packages\ultralytics\engine\model.py:128)
init (c:\Appl\Python\Lib\site-packages\ultralytics\engine\model.py:92)
(c:\Users\us0jsdn\Desktop\Workspaces\Python\Sandbox\yolov5\Pipelines\TrainFromScratch.py:9)
_run_code (c:\Appl\Python\Lib\runpy.py:86)
_run_module_as_main (Current frame) (c:\Appl\Python\Lib\runpy.py:196)

Output logger from ultralytics

                   from  n    params  module                                       arguments
  0                  -1  1      7040  ultralytics.nn.modules.conv.Conv             [3, 64, 6, 2, 2]
  1                  -1  1     73984  ultralytics.nn.modules.conv.Conv             [64, 128, 3, 2]
  2                  -1  3    156928  ultralytics.nn.modules.block.C3              [128, 128, 3]
  3                  -1  1    295424  ultralytics.nn.modules.conv.Conv             [128, 256, 3, 2]
  4                  -1  6   1118208  ultralytics.nn.modules.block.C3              [256, 256, 6]
  5                  -1  1   1180672  ultralytics.nn.modules.conv.Conv             [256, 512, 3, 2]
  6                  -1  9   6433792  ultralytics.nn.modules.block.C3              [512, 512, 9]
  7                  -1  1   4720640  ultralytics.nn.modules.conv.Conv             [512, 1024, 3, 2]
  8                  -1  3   9971712  ultralytics.nn.modules.block.C3              [1024, 1024, 3]
  9                  -1  1   2624512  ultralytics.nn.modules.block.SPPF            [1024, 1024, 5]
 10                  -1  1    525312  ultralytics.nn.modules.conv.Conv             [1024, 512, 1, 1]
 11                  -1  1         0  torch.nn.modules.upsampling.Upsample         [None, 2, 'nearest']
 12             [-1, 6]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 13                  -1  3   2757632  ultralytics.nn.modules.block.C3              [1024, 512, 3, False]
 14                  -1  1    131584  ultralytics.nn.modules.conv.Conv             [512, 256, 1, 1]
 15                  -1  1         0  torch.nn.modules.upsampling.Upsample         [None, 2, 'nearest']
 16             [-1, 4]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 17                  -1  3    690688  ultralytics.nn.modules.block.C3              [512, 256, 3, False]
 18                  -1  1    590336  ultralytics.nn.modules.conv.Conv             [256, 256, 3, 2]
 19            [-1, 14]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 20                  -1  3   2495488  ultralytics.nn.modules.block.C3              [512, 512, 3, False]
 21                  -1  1   2360320  ultralytics.nn.modules.conv.Conv             [512, 512, 3, 2]
 22            [-1, 10]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 23                  -1  3   9971712  ultralytics.nn.modules.block.C3              [1024, 1024, 3, False]        

Support materials

yolov5s.yaml

# YOLOv5 🚀 by Ultralytics, AGPL-3.0 license

# Parameters
nc: 1  # number of classes
depth_multiple: 1.0  # model depth multiple
width_multiple: 1.0  # layer channel multiple
anchors:
  - [10,13, 16,30, 33,23]  # P3/8
  - [30,61, 62,45, 59,119]  # P4/16
  - [116,90, 156,198, 373,326]  # P5/32

# YOLOv5 v6.0 backbone
backbone:
  # [from, number, module, args]
  [[-1, 1, Conv, [64, 6, 2, 2]],  # 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, 6, 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, 3, C3, [1024]],
   [-1, 1, SPPF, [1024, 5]],  # 9
  ]

# YOLOv5 v6.0 head
head:
  [[-1, 1, Conv, [512, 1, 1]],
   [-1, 1, nn.Upsample, [None, 2, 'nearest']],
   [[-1, 6], 1, Concat, [1]],  # cat backbone P4
   [-1, 3, C3, [512, False]],  # 13

   [-1, 1, Conv, [256, 1, 1]],
   [-1, 1, nn.Upsample, [None, 2, 'nearest']],
   [[-1, 4], 1, Concat, [1]],  # cat backbone P3
   [-1, 3, C3, [256, False]],  # 17 (P3/8-small)

   [-1, 1, Conv, [256, 3, 2]],
   [[-1, 14], 1, Concat, [1]],  # cat head P4
   [-1, 3, C3, [512, False]],  # 20 (P4/16-medium)

   [-1, 1, Conv, [512, 3, 2]],
   [[-1, 10], 1, Concat, [1]],  # cat head P5
   [-1, 3, C3, [1024, False]],  # 23 (P5/32-large)

   [[17, 20, 23], 1, Detect, [nc, anchors]],  # Detect(P3, P4, P5)
  ]

Please help me I cannot find a good solution despite the 80 tabs of S.O open

Environment

-YOLO: Yolov5
-OS: Windows 10
-Python Version: 3.10.4
-Pip Version: 23.1.2
-Ultralytics pip package: 8.0.22

Minimal Reproducible Example

TrainFromScratch.py

from ultralytics import YOLO
model = YOLO('path_to_yaml/yolov5l.yaml') 
res = model.train(PARAMS)

Additional

Thank you for reading this

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!
@JDang-At-Festo JDang-At-Festo added the bug Something isn't working label Jan 16, 2024
Copy link
Contributor

👋 Hello @JDang-At-Festo, 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 a minimum reproducible example to help us debug it.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset image examples and training logs, and verify you are following our Tips for Best Training Results.

Requirements

Python>=3.8.0 with all requirements.txt installed including PyTorch>=1.8. To get started:

git clone https://github.com/ultralytics/yolov5  # clone
cd yolov5
pip install -r requirements.txt  # install

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

YOLOv5 CI

If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training, validation, inference, export and benchmarks on macOS, Windows, and Ubuntu every 24 hours and on every commit.

Introducing YOLOv8 🚀

We're excited to announce the launch of our latest state-of-the-art (SOTA) object detection model for 2023 - YOLOv8 🚀!

Designed to be fast, accurate, and easy to use, YOLOv8 is an ideal choice for a wide range of object detection, image segmentation and image classification tasks. With YOLOv8, you'll be able to quickly and accurately detect objects in real-time, streamline your workflows, and achieve new levels of accuracy in your projects.

Check out our YOLOv8 Docs for details and get started with:

pip install ultralytics

@glenn-jocher
Copy link
Member

@JDang-At-Festo hello! Thank you for the detailed issue report. It seems like there might be a mismatch between the expected arguments in the Detect layer and the ones provided in your YAML configuration.

The Detect layer typically expects the number of classes (nc) and the anchor grid sizes (anchors) as arguments. In your YAML file, the Detect layer is defined with three arguments: [nc, anchors], which should be correct. However, the error suggests that an additional, unexpected argument is being passed to the Detect initializer.

Could you please ensure that you are using the latest version of the YOLOv5 repository and that your environment is set up according to the instructions in the Ultralytics Docs? If the issue persists, it might be helpful to check if there have been any changes to the Detect layer's expected arguments in the latest version.

If you're confident that your setup is correct and the issue is not resolved, please consider opening an issue on the YOLOv5 GitHub repository with the details provided here, and we'll look into it further.

In the meantime, you might want to try instantiating the model using the create method from the YOLO class, which is the recommended way to create a model for training:

from ultralytics import YOLO
model = YOLO.create('path_to_yaml/yolov5l.yaml', nc=1, anchors=your_anchors)

Replace your_anchors with the actual anchor values you intend to use.

Thank you for your contribution to the YOLOv5 community, and we appreciate your patience as we work to resolve this issue! 🚀

@JDang-At-Festo
Copy link
Author

Hello @glenn-jocher Thank you for the response! I will try this but in the meantime I was looking for the online documentation of the python package for ultralytics. I can only find the Tutorial of ultralytics. Is there more comprehensive documentation that I missed?

@glenn-jocher
Copy link
Member

Hello again @JDang-At-Festo-Festo! The link you've mentioned is indeed the primary source for Ultralytics YOLOv5 documentation. It provides a comprehensive guide on how to use the YOLOv5 Python package, including installation, setup, training, and inference.

If you're looking for more in-depth information, the documentation includes various sections that cover different aspects of using YOLOv5. For instance, the 'Tutorials' section provides step-by-step guides for common tasks, while the 'API' section details the functions and classes available in the package.

For the most detailed understanding, you might also consider exploring the source code directly on the GitHub repository, as it often contains comments and docstrings that can provide additional context and usage information.

If there's something specific you're struggling to find or if you have suggestions for improving the documentation, please feel free to share your feedback. We're always looking to improve and make sure our documentation meets the needs of our users. Thanks for your engagement with the YOLOv5 community! 🌟

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants