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

Can not import YOLO from ultralytics #2802

Closed
1 of 2 tasks
ngocnd2402 opened this issue May 24, 2023 · 10 comments
Closed
1 of 2 tasks

Can not import YOLO from ultralytics #2802

ngocnd2402 opened this issue May 24, 2023 · 10 comments
Labels
bug Something isn't working non-reproducible Bug is not reproducible Stale

Comments

@ngocnd2402
Copy link

Search before asking

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

YOLOv8 Component

No response

Bug

When i upgrade the newest ultralytics, it raise error so i can not use YOLOv5 or YOLOv8 :((( sorry for my poor english

Environment

No response

Minimal Reproducible Example

No response

Additional

No response

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!
@ngocnd2402 ngocnd2402 added the bug Something isn't working label May 24, 2023
@Kayzwer
Copy link
Contributor

Kayzwer commented May 24, 2023

after you done git pull, make sure you pip install -e . again, if you clone from source.

@ngocnd2402
Copy link
Author

after you done git pull, make sure you pip install -e . again, if you clone from source.

no, i just pip install ultralytics, and use "from ultralytics import YOLO"

@glenn-jocher
Copy link
Member

@Kayzwer thank you for your response. To clarify, if you are cloning the YOLOv8 source and doing a git pull to update, then you need to run pip install -e . again to ensure that the changes are reflected in your local installation. However, if you are installing the Ultralytics package from PyPI using pip install ultralytics, then you can import the YOLO class directly from ultralytics in your code with from ultralytics import YOLO. I hope this helps!

@glenn-jocher glenn-jocher added the non-reproducible Bug is not reproducible label May 29, 2023
@github-actions
Copy link

👋 Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help.

For additional resources and information, please see the links below:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLO 🚀 and Vision AI ⭐

@github-actions github-actions bot added the Stale label Jun 29, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jul 10, 2023
@ovidedecroly
Copy link

ovidedecroly commented Sep 21, 2023

@glenn-jocher I have cloned ultralithic for YOLOv8. How to modify the YOLOv8 architecture, for example by substituting new blocks that I designed myself or from the latest journal papers. Currently I am a Ph.D student doing research to identify microorganisms. I hope you can help me. Thank You

@glenn-jocher
Copy link
Member

@ovidedecroly hello,

Thank you for reaching out. It's really exciting to hear about your work in identifying microorganisms using YOLOv8.

To modify the YOLOv8 architecture with your own, custom-designed blocks, you need to go to the model's configuration file. Usually, this is a .yaml file in the /models directory. This file essentially describes the architecture of the YOLOv8 model block by block, layer by layer in a sequential manner.

To insert your blocks into this model, you need to define your blocks following the syntax presented in this .yaml file. Once you've defined your blocks, you can replace or add these new blocks into the desired position in the model's configuration.

Remember, your custom blocks might change the shapes of the input or output, so be cautious about maintaining compatibility across your changes. You also need to account for the parameters that are fed through each layer and ensure continuity.

Once you've updated the .yaml file, you can use it to train YOLOv8 using your adjusted model architecture. Keep in mind that if you make substantial changes in the model's architecture, you may need to tune hyper-parameters and adjust training configurations accordingly to optimize the model's performance.

We look forward to seeing how your works contribute to the YOLO community and the scientific community at large. Best of luck on your research!

Best wishes,
Glenn

@ovidedecroly
Copy link

ovidedecroly commented Sep 21, 2023

@glenn-jocher Hello,
I have a problem like this:
from ultralytics import YOLO
model = YOLO('yolov8.yaml') ImportError: cannot import name 'YOLO' from 'ultralytics' (unknown location)
Thank you

@glenn-jocher
Copy link
Member

@ovidedecroly hello,

Thank you for contacting us. It appears that there might be an issue with your installation or importing statement.

In the YOLOv8 repository, importing the YOLO class directly from 'ultralytics' is not how it's designed to operate. The YOLO class should be imported from the 'models' module in the Ultralytics YOLOv8 repo.

When you successfully install the Ultralytics YOLOv8 repository and all its dependencies, you should be able to import the YOLO class by first navigating to the correct directory where the 'models' module resides. Then you can execute 'from models import YOLO' to import the YOLO class.

Lastly, the 'YOLO' function takes the file path of the configuration file, which in your case is 'yolov8.yaml'. Please make sure 'yolov8.yaml' is in your current working directory or provide the absolute path of the 'yolov8.yaml' configuration file to the 'YOLO' function.

I hope this helps, and please let us know if you have additional issues.

@ovidedecroly
Copy link

@glenn-jocher hello
I want to change the YOLOv8 YAML by changing conv to Lightconv. Then I changed the previous C2F Bottleneck to Ghostbottleneck. When I replace C2F without replacing the Conv type with Lightconv in YAML, the YAML model can still be run. I have also changed the code in task.py, but when I replaced it with Lightconv the following error occurred:
RuntimeError Traceback (most recent call last)
in <cell line: 5>()
3 from ultralytics import YOLO
4
----> 5 models = YOLO('/content/ultralytics/ultralytics/cfg/models/v8/yolov8x.yaml')

8 frames
/usr/local/lib/python3.10/dist-packages/ultralytics/nn/modules/conv.py in forward(self, x)
292 def forward(self, x):
293 """Forward pass for the YOLOv8 mask Proto module."""
--> 294 return torch.cat(x, self.d)

RuntimeError: Sizes of tensors must match except in dimension 1. Expected size 512 but got size 256 for tensor number 1 in the list.

For the YAML that I changed.

Ultralytics YOLO 🚀, AGPL-3.0 license

YOLOv8 object detection model with P3-P5 outputs. For Usage examples see https://docs.ultralytics.com/tasks/detect

Parameters

nc: 20 # number of classes
scales: # model compound scaling constants, i.e. 'model=yolov8n.yaml' will call yolov8.yaml with scale 'n'

[depth, width, max_channels]

n: [0.33, 0.25, 1024] # YOLOv8n summary: 225 layers, 3157200 parameters, 3157184 gradients, 8.9 GFLOPs
s: [0.33, 0.50, 1024] # YOLOv8s summary: 225 layers, 11166560 parameters, 11166544 gradients, 28.8 GFLOPs
m: [0.67, 0.75, 768] #YOLOv8m summary: 295 layers, 25902640 parameters, 25902624 gradients, 79.3 GFLOPs
l: [1.00, 1.00, 512] # YOLOv8l summary: 365 layers, 43691520 parameters, 43691504 gradients, 165.7 GFLOPs
x: [1.00, 1.25, 512] # YOLOv8x summary: 365 layers, 68229648 parameters, 68229632 gradients, 258.5 GFLOPs

#YOLOv8.0n backbone
backbone:

[from, repeats, module, args]

  • [-1, 1, LightConv, [64, 3, 2]] #0-P1/2
  • [-1, 1, LightConv, [128, 3, 2]] Initial pip structure #1-P2/4
  • [-1, 3, C2f, [128, True]]
  • [-1, 1, LightConv, [256, 3, 2]] #3-P3/8
  • [-1, 6, C2f, [256, True]]
  • [-1, 1, LightConv, [512, 3, 2]] #5-P4/16
  • [-1, 6, C2f, [512, True]]
  • [-1, 1, LightConv, [1024, 3, 2]] #7-P5/32
  • [-1, 3, C2f, [1024, True]]
  • [-1, 1, SPPF, [1024, 5]] Update requirements.txt #9

#YOLOv8.0n head
head:

Thanks

@glenn-jocher
Copy link
Member

@ovidedecroly hello,

It appears you're encountering an error when integrating LightConv layers into your YOLOv8 model. The error message is suggesting that there is a mismatch in tensor sizes, possibly due to the changes you made with replacing Conv with LightConv.

LightConv layers might be outputting different tensor sizes than the standard Conv layers which were originally used in the model. The subsequent layers or operations (like concatenation) expect a certain input size, if it does not match they throw this kind of error.

To fix this, you'll need to understand and align the expected tensor size between each of your layers by either adjusting the way the inputs or outputs are handled with your new LightConv layers, or accommodating the new sizes in the subsequent layers in your model. It requires a good understanding of how each of these custom layers modifies the input tensor.

Also, keep in mind that when we modify the architecture YAML file, we must ensure that the changes are propagated effectively in the corresponding model files.

Best of luck with your research, it sounds like an interesting adaption of the YOLOv8 model!

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

No branches or pull requests

4 participants