hub
hub copied to clipboard
AttributeError: partially initialized module 'ultralytics.models.yolo' has no attribute 'detect' (most likely due to a circular import)
Search before asking
- [X] I have searched the HUB issues and found no similar bug report.
HUB Component
No response
Bug
Hello, I'm trying to train a model on my computer but i run into this error: AttributeError Traceback (most recent call last) Cell In[6], line 2 1 from roboflow import Roboflow ----> 2 from ultralytics import YOLO
File ~\AppData\Roaming\Python\Python312\site-packages\ultralytics_init_.py:5 1 # Ultralytics YOLO π, AGPL-3.0 license 3 version = "8.1.39" ----> 5 from ultralytics.data.explorer.explorer import Explorer 6 from ultralytics.models import RTDETR, SAM, YOLO, YOLOWorld 7 from ultralytics.models.fastsam import FastSAM
File ~\AppData\Roaming\Python\Python312\site-packages\ultralytics\data\explorer\explorer.py:18 16 from ultralytics.data.dataset import YOLODataset 17 from ultralytics.data.utils import check_det_dataset ---> 18 from ultralytics.models.yolo.model import YOLO 19 from ultralytics.utils import LOGGER, IterableSimpleNamespace, checks, USER_CONFIG_DIR 20 from .utils import get_sim_index_schema, get_table_schema, plot_query_result, prompt_sql_query, sanitize_batch
File ~\AppData\Roaming\Python\Python312\site-packages\ultralytics\models_init_.py:5 3 from .rtdetr import RTDETR 4 from .sam import SAM ----> 5 from .yolo import YOLO, YOLOWorld 7 all = "YOLO", "RTDETR", "SAM", "YOLOWorld" # allow simpler import ... 42 ``` 43 """ 45 def init(self, cfg=DEFAULT_CFG, overrides=None, _callbacks=None):
AttributeError: partially initialized module 'ultralytics.models.yolo' has no attribute 'detect' (most likely due to a circular import)
I installed ultralytics using this command: pip install ultralytics and everything went smoothly.
But then when i run my python script i got the error.
yolov8 training - new method from ultralytics import YOLO
model = YOLO("D:\UFCSPA\TCC II\yolov8m.pt") results_train = model.train(data="D:\UFCSPA\TCC II\Allergen-30---Anotation-6\Allergen30 - My Classes\data.yaml", epochs=150, batch=-1, imgsz=416, save=True, plots=True, task='detect')
Any idea on this issue ?
Thank you!
Environment
Windows 11 Info about VSCode
- VersΓ£o: 1.87.2 (user setup)
- Confirmar: 863d2581ecda6849923a2118d93a088b0745d9d6
- Data: 2024-03-08T15:20:17.278Z
- Electron: 27.3.2
- ElectronBuildId: 26836302
- Chromium: 118.0.5993.159
- Node.js: 18.17.1
- V8: 11.8.172.18-electron.0
- SO: Windows_NT x64 10.0.22631 Python 3.12
Minimal Reproducible Example
I just tried to import YOLO using the import command trough the ultralytics library.
Additional
My list of packages: Package Version
asttokens 2.4.1 beautifulsoup4 4.12.3 bitly_api 0.3 bitly-api-python 1.0.3 certifi 2023.7.22 chardet 4.0.0 charset-normalizer 3.3.2 clip 0.2.0 colorama 0.4.6 comm 0.2.2 contourpy 1.2.0 cycler 0.10.0 debugpy 1.8.1 decorator 5.1.1 executing 2.0.1 facebook-sdk 3.1.0 filelock 3.13.3 fonttools 4.50.0 fsspec 2024.3.1 idna 2.10 ipykernel 6.29.4 ipython 8.23.0 jedi 0.19.1 Jinja2 3.1.3 jupyter_client 8.6.1 jupyter_core 5.7.2 kiwisolver 1.4.5 lxml 5.1.0 MarkupSafe 2.1.5 matplotlib 3.8.3 matplotlib-inline 0.1.6 mpmath 1.3.0 nest-asyncio 1.6.0 networkx 3.2.1 numpy 1.26.4 opencv-python 4.9.0.80 opencv-python-headless 4.8.0.74 packaging 24.0 pandas 2.2.1 parso 0.8.3 pillow 10.2.0 pip 24.0 platformdirs 4.2.0 prompt-toolkit 3.0.43 psutil 5.9.8 pure-eval 0.2.2 py-cpuinfo 9.0.0 Pygments 2.17.2 pyparsing 3.1.2 pyshorteners 1.0.1 python-dateutil 2.9.0.post0 python-dotenv 1.0.1 python-magic 0.4.27 pytz 2024.1 pywin32 306 PyYAML 6.0.1 pyzmq 25.1.2 requests 2.31.0 requests-toolbelt 1.0.0 roboflow 1.1.26 scipy 1.12.0 seaborn 0.13.2 six 1.16.0 soupsieve 2.5 stack-data 0.6.3 sympy 1.12 thop 0.1.1.post2209072238 torch 2.2.2+cu121 torchaudio 2.2.2+cu121 torchvision 0.17.2 tornado 6.4 tqdm 4.66.2 traitlets 5.14.2 typing_extensions 4.10.0 tzdata 2024.1 ultralytics 8.1.39 urllib3 2.2.1 wcwidth 0.2.13
π Hello @RodrigoSeger, thank you for raising an issue about Ultralytics HUB π! Please visit our HUB Docs to learn more:
- Quickstart. Start training and deploying YOLO models with HUB in seconds.
- Datasets: Preparing and Uploading. Learn how to prepare and upload your datasets to HUB in YOLO format.
- Projects: Creating and Managing. Group your models into projects for improved organization.
- Models: Training and Exporting. Train YOLOv5 and YOLOv8 models on your custom datasets and export them to various formats for deployment.
- Integrations. Explore different integration options for your trained models, such as TensorFlow, ONNX, OpenVINO, CoreML, and PaddlePaddle.
- Ultralytics HUB App. Learn about the Ultralytics App for iOS and Android, which allows you to run models directly on your mobile device.
- Inference API. Understand how to use the Inference API for running your trained models in the cloud to generate predictions.
If this is a π Bug Report, please provide screenshots and steps to reproduce your problem to help us get started working on a fix.
If this is a β Question, please provide as much information as possible, including dataset, model, environment details etc. so that we might provide the most helpful response.
We try to respond to all issues as promptly as possible. Thank you for your patience!
@RodrigoSeger hi there! π It looks like you're encountering an AttributeError due to a possible circular import issue when trying to use the Ultralytics library. This type of error can sometimes happen when importing modules in a way that they end up trying to import each other, leading to a deadlock where neither can fully load before the other. Here are a couple of suggestions you might find helpful:
-
Check Your Import Statements: Ensure that you're importing the Ultralytics modules in the recommended order and manner as per the documentation. Sometimes, rearranging import statements can resolve circular import issues.
-
Update Ultralytics Package: Although it seems you've installed the Ultralytics package without issues, there might have been updates or fixes released since. Try updating the package to the latest version using your package manager.
-
Environment Check: Make sure that your Python environment is set up correctly and that there are no conflicts between different versions of the packages you've installed. Creating a fresh virtual environment and reinstalling your dependencies might help isolate the issue.
-
Dependencies: Review the list of installed packages for any potential conflicts or incompatible versions that might be causing the problem. You can compare the versions of the critical dependencies like
torch,torchvision,numpy, etc., with those recommended by Ultralytics for compatibility.
For more detailed guidelines and troubleshooting tips, please visit our Ultralytics HUB Docs at https://docs.ultralytics.com/hub. If the problem persists even after trying these steps, feel free to provide further details in this issue thread, including any changes or tests you've tried. This will help us assist you more effectively. π οΈ
Thank you for reaching out, and we appreciate your patience as we work through this issue together!
π 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:
- Docs: https://docs.ultralytics.com
- HUB: https://hub.ultralytics.com
- Community: https://community.ultralytics.com
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 β