دليل شامل إلى Ultralytics YOLOv5#
صُمم YOLOv5 من Ultralytics، وهو الإصدار الخامس من نموذج اكتشاف الكائنات «You Only Look Once»، لتقديم نتائج سريعة ودقيقة في الوقت الفعلي. لا يزال YOLOv5 مستخدمًا على نطاق واسع، لكن خلفاءه Ultralytics YOLOv8 وYOLO11 وYOLO26 يقدمون أحدث التطورات، ويُوصى بـYOLO26 للمشاريع الجديدة.
بُني YOLOv5 على PyTorch، وهو إطار عمل شائع لـالتعلم العميق، ويشتهر بتعدد استخداماته وسهولة استخدامه وأدائه. تتناول هذه الوثائق التثبيت وبنية النموذج وحالات الاستخدام الشائعة وسلسلة من البرامج التعليمية المفصلة لمساعدتك على تطبيق YOLOv5 في مشاريع الرؤية الحاسوبية الخاصة بك.
استكشف وتعلّم#
ترشدك هذه البرامج التعليمية إلى جوانب مختلفة من YOLOv5:
- تدريب البيانات المخصصة (موصى به): تعرّف على كيفية تدريب نموذج YOLOv5 على مجموعة البيانات المخصصة الخاصة بك.
- نصائح للحصول على أفضل نتائج التدريب: اكتشف نصائح عملية لتحسين عملية تدريب النموذج.
- التدريب باستخدام وحدات GPU متعددة: تعرّف على كيفية استخدام وحدات GPU متعددة لتسريع التدريب.
- PyTorch Hub: تعلّم تحميل النماذج المدرّبة مسبقًا عبر PyTorch Hub.
- التصدير إلى TFLite وONNX وCoreML وTensorRT: تعرّف على كيفية تصدير نموذجك إلى تنسيقات مختلفة.
- زيادة البيانات وقت الاختبار (TTA): استكشف كيفية استخدام TTA لتحسين دقة تنبؤات النموذج.
- دمج النماذج: تعلّم استراتيجية الجمع بين نماذج متعددة لتحسين الأداء.
- تقليص النموذج/التناثر: تعرّف على مفهومي التقليص والتناثر، وكيفية إنشاء نموذج أكثر كفاءة.
- تطوير المعلمات الفائقة: اكتشف عملية ضبط المعلمات الفائقة آليًا لتحسين أداء النموذج.
- التعلّم بالنقل باستخدام الطبقات المجمّدة: تعلّم كيفية تطبيق التعلّم بالنقل عبر تجميد الطبقات في YOLOv5.
- ملخص البنية: تعرّف على التفاصيل البنيوية لنموذج YOLOv5.
- تكامل تسجيل ClearML: تعرّف على كيفية دمج ClearML لتسجيل البيانات أثناء تدريب النموذج.
- YOLOv5 مع Neural Magic: اكتشف كيفية استخدام DeepSparse من Neural Magic لتقليص نموذج YOLOv5 وتكميمه.
- تكامل تسجيل Comet: تعرّف على كيفية استخدام Comet لتسجيل عمليات التدريب وتصويرها.
البيئات المدعومة#
توفر Ultralytics مجموعة من البيئات الجاهزة للاستخدام، وكل منها مثبت مسبقًا مع التبعيات الأساسية مثل CUDA وcuDNN وPython وPyTorch، لتتمكن من بدء المشاريع بسرعة. ويمكنك أيضًا إدارة النماذج ومجموعات البيانات باستخدام منصة Ultralytics.
- دفاتر GPU مجانية:
- Google Cloud: دليل البدء السريع لـ GCP
- Amazon: دليل البدء السريع لـ AWS
- Azure: دليل البدء السريع لـ AzureML
- Docker: دليل البدء السريع لـ Docker
حالة المشروع#
تشير هذه الشارة إلى اجتياز جميع اختبارات التكامل المستمر (CI) الخاصة بـ إجراءات YOLOv5 على GitHub بنجاح. وتتحقق اختبارات CI بدقة من وظائف YOLOv5 وأدائه في جوانب رئيسية متعددة: التدريب والتحقق والاستدلال والتصدير واختبارات الأداء. وهي تضمن التشغيل المتسق والموثوق على macOS وWindows وUbuntu، مع إجراء الاختبارات كل 24 ساعة وعند كل إيداع جديد.
تواصل وساهم#
انضم إلى مجتمع Ultralytics على GitHub، وتواصل مع المحترفين على LinkedIn، وشارك نتائجك على Twitter، واعثر على موارد تعليمية على YouTube. تابعنا على TikTok وBiliBili لمزيد من المحتوى.
هل ترغب في المساهمة؟ نرحب بالمساهمات بمختلف أشكالها، من تحسينات الشيفرة البرمجية وتقارير الأخطاء إلى تحديثات الوثائق. اطّلع على إرشادات المساهمة لمزيد من المعلومات.
الأسئلة الشائعة#
يشتهر Ultralytics YOLOv5 بسرعة اكتشاف الكائنات ودقته العالية الدقة في الوقت الفعلي. وقد بُني على PyTorch، وهو متعدد الاستخدامات وسهل الاستخدام، ما يجعله مناسبًا لمشاريع الرؤية الحاسوبية المتنوعة. وتشمل ميزاته الرئيسية الاستدلال في الوقت الفعلي، ودعم تقنيات الاستدلال مثل تعزيز وقت الاختبار (TTA) وتجميع النماذج، والتوافق مع تنسيقات التصدير مثل TFLite وONNX وCoreML وTensorRT.
يتطلب تدريب نموذج YOLOv5 مخصص على مجموعة بياناتك بضع خطوات أساسية. أولًا، جهّز مجموعة البيانات بالتنسيق المطلوب وأضف إليها التسميات التوضيحية. ثم أعدّ معلمات تدريب YOLOv5 وابدأ عملية التدريب باستخدام النص البرمجي
train.py.غالبًا ما يُفضّل Ultralytics YOLOv5 على نماذج مثل R-CNN لسرعته ودقته في اكتشاف الكائنات في الزمن الحقيقي. وبصفته كاشفًا أحادي المرحلة، يعالج YOLOv5 الصورة كاملةً في تمريرة واحدة، ما يجعله أسرع بكثير من النهج القائم على المناطق في R-CNN، الذي يتضمن تمريرات متعددة. كما أن دعمه لتنسيقات تصدير كثيرة ووثائقه الشاملة يجعلان منه خيارًا مناسبًا للمبتدئين والمحترفين على حد سواء.
يتطلب تحسين أداء نموذج YOLOv5 ضبط معلمات فائقة متنوعة ودمج تقنيات مثل زيادة البيانات والتعلم بالنقل. توفر Ultralytics أدلة حول تطور المعلمات الفائقة والتقليم/التناثر لتحسين كفاءة النموذج، ويجمع دليل نصائح الحصول على أفضل نتائج التدريب إرشادات عملية للتدريب.
يدعم Ultralytics YOLOv5 مجموعة متنوعة من البيئات، بما فيها دفاتر GPU المجانية على Gradient وGoogle Colab وKaggle، إضافةً إلى منصات سحابية رئيسية مثل Google Cloud وAmazon AWS وAzure. تتوفر أيضًا صور Docker لتسهيل الإعداد. للحصول على دليل مفصل لإعداد هذه البيئات، راجع قسم البيئات المدعومة، الذي يتضمن تعليمات خطوة بخطوة لكل منصة.
التعليقات33
sustaintipsdeveloper Hello, I wanted to calculate the accuracy of the YOLOv5. I'm doing a physical testing. Can you recommend me, what is the formula that can I used for this physical testing? Is the formula will be like this? Accuracy = Sum of Confidence Score/Total Test Cases × 100
Glenn JocherUltralytics @sustaintipsdeveloper the formula you mentioned,
Accuracy = Sum of Confidence Score / Total Test Cases × 100, is not typically used to calculate accuracy in object detection. Instead, metrics like Mean Average Precision (mAP) and Intersection over Union (IoU) are commonly used. You can refer to the YOLOv5 documentation for guidance on evaluating model performance using these metrics. Let me know if you need further clarification!1sustaintipsdeveloper Sir, how about the confidence level? What's the formula? Thank you
Glenn JocherUltralytics The confidence level in YOLO models is the score that represents the model's certainty that a detected object belongs to a particular class. It is not calculated manually but is an output of the model, ranging from 0 to 1. You can adjust the confidence threshold during inference to filter predictions. For more details on confidence scores, refer to the YOLOv5 documentation. Let me know if you need further clarification!
1
Vidhul-S Hello i am new to this but her i go, i am supposed to create a streamlined way to run a yolov5 model on a jetson nano since it runs runs ubuntu 18.04 and torch limitations i decided to go with virtual environment But i am still limited to python 3.6.9 because the last compiled torch available 1.10.0 only works on 3.6.9 or lower So i had to use an older version of yolov5 namely Yolov5 v6.1 on the nano Now i am training my models on a much better system and only inferencing on the nano My issue starts here First i Tried to train a model on yolov5 v7.0 (latest one) and tried to inference in on nano and obviously it didn't run so i tried to checkout v6.1 on my system but i am un able to get it running due to the dependencies I tried everything i can think off ranging from using different python version and environments to modifying the requirements.txt to forcefully chance the versions ,I couldn't get a working project which can train models can anyone provide me a working set of versions of all these packages to install . Or link to a project with yolov5 v6.1
Note:
The machine i am training models on is a really capable one so no issue in that front I am not a programmer and still learning so pardon me for anything wrong above English is not my first language so if anything is confusing firstly i am sorry feel free to ask for any clarification
Vidhul-S let me know if there is any other way i can get yolov5 running on jetson nano with pytorch 1.10.0 python3.6.9
Glenn JocherUltralytics @Vidhul-S running YOLOv5 on a Jetson Nano with PyTorch 1.10.0 and Python 3.6.9 can be challenging due to compatibility issues. Given your constraints, using YOLOv5 v6.1 is a reasonable approach. To streamline your workflow, ensure you match the dependencies of YOLOv5 v6.1 on both your training system and the Jetson Nano. You can find the specific versions of dependencies in the
requirements.txtfile of the YOLOv5 v6.1 repository. If you encounter issues, consider using Docker to create a consistent environment across different systems. For further guidance, refer to the YOLOv5 documentation.
dalmeidalorraine Does YOLO v5 support multi label classification? If yes, where can I find some examples and documentation?
Paula DerrengerUltralytics Yes, YOLOv5 does support multi-label classification. You can find examples and detailed documentation on how to train YOLOv5 on your custom dataset, which can include multi-label scenarios, in our comprehensive guide. Please refer to the "Train Custom Data" section of the YOLOv5 documentation for step-by-step instructions and tips to optimize your training process. This will help you effectively handle multiple labels per image in your projects. Happy modeling! 🚀
roihanmjd i have a problem like this : (base) D:\yolov5update\yolov5>python detect.py Traceback (most recent call last): File "D:\yolov5update\yolov5\detect.py", line 38, in <module> import torch File "C:\Users\ASUS\AppData\Roaming\Python\Python311\site-packages\torch_init_.py", line 141, in <module> raise err OSError: [WinError 126] The specified module could not be found. Error loading "C:\Users\ASUS\AppData\Roaming\Python\Python311\site-packages\torch\lib\shm.dll" or one of its dependencies.
Paula DerrengerUltralytics It looks like there's an issue with loading the PyTorch library due to a missing
shm.dllfile. This can happen if the PyTorch installation is incomplete or corrupted. Here are a few steps to resolve this:-
Reinstall PyTorch: Ensure you have the correct version of PyTorch installed for your Python version. You can reinstall it using pip:
pip install torch --force-reinstall -
Check System Path: Ensure that the path to your Python environment is correctly set in your system's PATH variable.
-
Dependencies: Sometimes, missing system dependencies can cause this error. You might want to ensure all necessary system dependencies for PyTorch are installed.
If the issue persists after trying these steps, consider reinstalling Python and PyTorch in a new virtual environment. This can sometimes resolve hidden conflicts or corrupted installations.
-
dalmeidalorraine Does YOLO v5 support multi label classification? If yes, where can I find some examples and documentation?
Paula DerrengerUltralytics @dalmeidalorraine yes, YOLOv5 supports multi-label classification! You can train a model to detect multiple labels per detection by adjusting your dataset annotations to reflect multiple classes per bounding box. For examples and more detailed instructions on setting this up, please refer to the "Train Custom Data" section of our comprehensive YOLOv5 documentation. This section will guide you through the process of training YOLOv5 on your custom dataset, which can include multi-label scenarios. Happy modeling! 🚀
ShashankMPatil Why i am not able to open webcam
import cv2 import numpy as np import torch
my best.pt is in content folder
model = torch.hub.load('ultralytics/yolov5', 'custom', path='/content/best.pt', force_reload=True)
cap =cv2.VideoCapture(2) while cap.isOpened(): ret,frame=cap.read()
results=model(frame)
cv2.imshow("YOLO", np.squeeze(results.render()))
even if i enter below code , webcam doesn't open !python detect.py --source 0
if cv2.waitKey(10) & 0xFF == ord('q'): break
cap.release() cv2.destroyAllWindows()
ShashankMPatil the code is bit jumbled, i hope you get what i am asking
Glenn JocherUltralytics It looks like you're having trouble with opening the webcam using OpenCV and YOLOv5. Here are a few things you might want to check:
-
Webcam Index: Ensure that the webcam index you are using (
2in your case) is correct. Typically, the default webcam is at index0. If you have multiple cameras, you might need to try different indices like0or1. -
Camera Permissions: Make sure that your system has the necessary permissions to access the webcam.
-
Code Check: Ensure that your code for opening the webcam and reading frames is correct. Here's a simplified version to test webcam functionality:
import cv2 cap = cv2.VideoCapture(0) # Try changing this index to 0 or 1 if not cap.isOpened(): print("Cannot open camera") exit() while True: ret, frame = cap.read() if not ret: print("Can't receive frame (stream end?). Exiting ...") break cv2.imshow('frame', frame) if cv2.waitKey(1) == ord('q'): break cap.release() cv2.destroyAllWindows() -
Driver Issues: Sometimes, driver issues can prevent access to the webcam. Ensure your device drivers are up to date.
If you're still facing issues, it might be helpful to provide more details or check the camera with other software to isolate the problem.
-
ghitabnr hello please i trained the yolov5 in my custom dataset that contains two classes but when i do the test the two classes show up with very close colors ( red and pink ) i want to the change the color of the boxes of detection? how please ?
Glenn JocherUltralytics @ghitabnr hi there! 👋 Changing the color of detection boxes in YOLOv5 involves modifying the
plot_one_box()function typically found in theutils/plots.pyfile. You'll have the flexibility to assign different colors to different classes.Here's a quick example of how you can modify it:
-
Locate the
plot_one_box()function. -
Inside this function, you'll find a line that sets the color. Modify this line to choose your colors based on class IDs. For instance:
color = colors[int(cls)] # default color selectionChange to:
colors = [[0,255,0], [255,0,0]] # Define colors for each class, e.g., green and blue color = colors[int(cls)]
Remember to define enough colors for each class you have to distinguish them clearly.
Hope this helps! Let me know if there's anything else you'd like to tweak! 🚀
-
Sequential-circuits Trying it in an nvidia jetson nano with jetpack 4.6 installed and getting AttributeError: partially initialized module 'cv2' has no attribute '_registerMatType' (most likely due to a circular import)
Paula DerrengerUltralytics @Sequential-circuits hey there! It looks like you're facing an
AttributeErrorrelated to OpenCV on your NVIDIA Jetson Nano. This issue might indeed be tied to a circular import or an incompatible OpenCV version. 😕Here's a quick suggestion:
- Ensure OpenCV is correctly installed and updated. Sometimes, reinstalling can help resolve strange errors. You can reinstall OpenCV using:
Given the NVIDIA platform, ensure all dependencies and JetPack SDK components are compatible and up-to-date.
pip install opencv-python-headless --force-reinstall
If the issue persists, consider checking the OpenCV installation specific to Jetson devices or exploring the NVIDIA forums for any JetPack-related quirks. The Jetson community is quite active and may have encountered similar issues.
Wishing you smoother sailing ahead! 🚀 If you have more questions or updates, feel free to reach out.
- Ensure OpenCV is correctly installed and updated. Sometimes, reinstalling can help resolve strange errors. You can reinstall OpenCV using:
nickguim Is there any tutorials on utilizing an object tracker such as deepsort or sort with an older model like yolov5? Everytime I attempt to use a github I have found something breaks
Paula DerrengerUltralytics Hi there! 👋 It seems like you're looking to use an object tracker like deepsort or sort with YOLOv5 and encountering some issues. While specific tutorials on integrating these trackers with older models like YOLOv5 might not be readily available on our documentation, I suggest checking out the YOLOv5 GitHub repo or community discussions for any shared solutions or advice from other users who might have attempted something similar.
Integration usually involves passing YOLOv5 detection outputs as inputs to the tracker. Here's a very basic snippet to give you an idea of how you might start:
# Assuming 'detections' is a list of detections from YOLOv5, # and 'tracker' is an instance of your tracking algorithm (e.g., deepsort) for detection in detections: bbox, confidence, class_id = detection # Convert bbox from x1y1x2y2 to xywh format expected by some trackers xywh_bbox = convert_to_xywh(bbox) # Now, you can update your tracker per frame tracker.update(xywh_bbox, confidence, class_id)Unfortunately, integrating third-party trackers can sometimes lead to compatibility issues due to updates or differences in expected inputs/outputs. If specifics break, consider checking:
- The version compatibility between YOLOv5 and the tracking library.
- The format of the detection outputs and expected tracker inputs.
- Any recent changes or updates in the tracker's source code that might affect integration.
For troubleshooting, I'd recommend revisiting the tracker documentation or seeking help directly from the tracker's GitHub page. Sometimes, the community might have already provided solutions for similar issues. 🛠️
Let us know if you encounter any specific errors or need further guidance! Our community is always here to help. Good luck with your project!
mature-1111 Yes,I do it. I have converted from json format with Polygon labels to YOLOv7 instance segmentation. The solution to this problem is to use hyp.scratch-high.yaml but set mixup to 0.0
天空 @.***
------------------ 原始邮件 ------------------ 发件人: "Glenn @.>; 发送时间: 2024年4月18日(星期四) 上午6:56 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [ultralytics/ultralytics] yolov5/ (Discussion #8575)
Hi there 👋! It seems like you're encountering an issue with dimension mismatch during the mixup augmentation process in YOLOv9's instance segmentation. This error typically occurs when the arrays you're trying to concatenate don't have the same shape — in this case, a discrepancy between the number of dimensions.
Without seeing the exact code or data structure you're working with, it's a bit difficult to provide a precise solution. However, one common approach is to ensure that both arrays being concatenated (segments and segments2) have the same dimensionality before performing the operation. For instance, if segments is a 1D array and segments2 is 3D, you might need to reshape or pad segments to match the dimensionality of segments2.
Here's a rough example of how to ensure they have the same number of dimensions: import numpy as np # Assuming segments is 1D and segments2 is 3D # Reshape or pad segments to make its dimensions compatible with segments2 segments = np.expand_dims(segments, axis=(1, 2)) # Adjust this based on your specific shapes # Now that both have the same number of dimensions, concatenate should work segments_combined = np.concatenate((segments, segments2), 0)
Remember, the key here is to adjust the dimensions so they're compatible. The exact method (expand_dims, reshape, pad, etc.) will depend on your data.
If you continue to face issues, could you provide more details or a snippet of the code where this error occurs? That way, we can offer more targeted advice. Happy coding! 🚀
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>
Glenn JocherUltralytics Hey there! 😊 It's great to hear you've successfully transitioned from JSON format with Polygon labels to YOLOv7 instance segmentation using the
hyp.scratch-high.yamland tweaking mixup to0.0. It sounds like you encountered a similar dimensionality issue during augmentation in YOLOv9 as discussed previously.For dimension mismatch errors, ensuring that both arrays to be concatenated have matching shapes is indeed crucial. The previous suggestion to harmonize dimensions using operations like
np.expand_dimsorreshapebefore concatenation is a solid approach 👍.Your initiative to share your solution and actively participate in this discussion enriches the community. If you hit any other snags or have further insights, feel free to share. Happy coding! 🚀
mature-1111 Traceback (most recent call last): File "D:/zyqi/yolov9-main/segment/train.py", line 646, in <module> main(opt) File "D:/zyqi/yolov9-main/segment/train.py", line 542, in main train(opt.hyp, opt, device, callbacks) File "D:/zyqi/yolov9-main/segment/train.py", line 270, in train for i, (imgs, targets, paths, _, masks) in pbar: # batch ------------------------------------------------------ File "D:\anaconda3\envs\yolov9\lib\site-packages\tqdm\std.py", line 1181, in iter for obj in iterable: File "D:\zyqi\yolov9-main\utils\dataloaders.py", line 170, in iter yield next(self.iterator) File "D:\anaconda3\envs\yolov9\lib\site-packages\torch\utils\data\dataloader.py", line 628, in next data = self._next_data() File "D:\anaconda3\envs\yolov9\lib\site-packages\torch\utils\data\dataloader.py", line 671, in _next_data data = self._dataset_fetcher.fetch(index) # may raise StopIteration File "D:\anaconda3\envs\yolov9\lib\site-packages\torch\utils\data_utils\fetch.py", line 58, in fetch data = [self.dataset[idx] for idx in possibly_batched_index] File "D:\anaconda3\envs\yolov9\lib\site-packages\torch\utils\data_utils\fetch.py", line 58, in <listcomp> data = [self.dataset[idx] for idx in possibly_batched_index] File "D:\zyqi\yolov9-main\utils\segment\dataloaders.py", line 116, in getitem img, labels, segments = mixup(img, labels, segments, *self.load_mosaic(random.randint(0, self.n - 1))) File "D:\zyqi\yolov9-main\utils\segment\augmentations.py", line 16, in mixup segments = np.concatenate((segments, segments2), 0) File "<array_function internals>", line 200, in concatenate ValueError: all the input arrays must have same number of dimensions, but the array at index 0 has 1 dimension(s) and the array at index 1 has 3 dimension(s)
mature-1111 The problem appear in yolov9 Instance Segmentation
Glenn JocherUltralytics Hi there 👋! It seems like you're encountering an issue with dimension mismatch during the mixup augmentation process in YOLOv9's instance segmentation. This error typically occurs when the arrays you're trying to concatenate don't have the same shape — in this case, a discrepancy between the number of dimensions.
Without seeing the exact code or data structure you're working with, it's a bit difficult to provide a precise solution. However, one common approach is to ensure that both arrays being concatenated (segments and segments2) have the same dimensionality before performing the operation. For instance, if
segmentsis a 1D array andsegments2is 3D, you might need to reshape or padsegmentsto match the dimensionality ofsegments2.Here's a rough example of how to ensure they have the same number of dimensions:
import numpy as np # Assuming segments is 1D and segments2 is 3D # Reshape or pad segments to make its dimensions compatible with segments2 segments = np.expand_dims(segments, axis=(1, 2)) # Adjust this based on your specific shapes # Now that both have the same number of dimensions, concatenate should work segments_combined = np.concatenate((segments, segments2), 0)Remember, the key here is to adjust the dimensions so they're compatible. The exact method (
expand_dims,reshape,pad, etc.) will depend on your data.If you continue to face issues, could you provide more details or a snippet of the code where this error occurs? That way, we can offer more targeted advice. Happy coding! 🚀








