Closed Elektrikci21 closed 3 years ago
π Hello @Elektrikci21, 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://ultralytics.com or email Glenn Jocher at glenn.jocher@ultralytics.com.
Python>=3.6.0 with all requirements.txt installed including PyTorch>=1.7. To get started:
$ git clone https://github.com/ultralytics/yolov5
$ cd yolov5
$ pip install -r requirements.txt
YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):
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), validation (val.py), inference (detect.py) and export (export.py) on MacOS, Windows, and Ubuntu every 24 hours and on every commit.
@Elektrikci21 it appears you may have environment problems. Please ensure you meet all dependency requirements if you are attempting to run YOLOv5 locally. If in doubt, create a new virtual Python environment, clone the latest repo (code changes daily), and pip install -r requirements.txt
again. We also highly recommend using one of our verified environments below.
Python>=3.6.0 with all requirements.txt installed including PyTorch>=1.7. To get started:
$ git clone https://github.com/ultralytics/yolov5
$ cd yolov5
$ pip install -r requirements.txt
YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):
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), validation (val.py), inference (detect.py) and export (export.py) on MacOS, Windows, and Ubuntu every 24 hours and on every commit.
@glenn-jocher I did everything from scratch but it does not work again.
@Elektrikci21 I'm suggesting you add many more samples to your training data set, ideally >1k images. From my experience anything less than 250-350 images per class you might have trouble getting any meaningful results.
Also, make sure your labels are correct and if possible add background images to your model by adding images with a blank or empty label txt file that do not include things you have labeled. Ideally you would have over 1k samples and maybe 100 background images. I have over 10k samples for most of my classes now after having only started with about 1k. Trying to train with too few images is a very common issue people have.
If you want a good data set to train with you can download a pre configured data set with good labels to see how your data set differs from a large well labeled data set.
https://docs.ultralytics.com/yolov5/tutorials/train_custom_data
This is the most important bit, if you want this to work read this and follow it.
https://docs.ultralytics.com/guides/model-training-tips/
Also make sure your training data set is representative of the input data you expect -- eg don't make all super high end images then take inference images with a 1950s web cam. Try to get training data from real world examples of how you expect data to come in.
I get the same problem, when it works on GPU, the box, obj, cls are nan and ap is 0, but when it works on CPU, you can get the correct results
@MangoloD it appears you may have environment problems. Please ensure you meet all dependency requirements if you are attempting to run YOLOv5 locally. If in doubt, create a new virtual Python 3.8 environment, clone the latest repo (code changes daily), and pip install -r requirements.txt
again. We also highly recommend using one of our verified environments below.
Python>=3.6.0 with all requirements.txt installed including PyTorch>=1.7. To get started:
$ git clone https://github.com/ultralytics/yolov5
$ cd yolov5
$ pip install -r requirements.txt
YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):
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), validation (val.py), inference (detect.py) and export (export.py) on MacOS, Windows, and Ubuntu every 24 hours and on every commit.
Perhaps this is a GPU issue? I have a GPU from the 16 series like Elektrikci21, an Nvidia GTX 1660 Ti, and my training would always produce nan values from epoch 0. I fixed this by switching to an Nvidia GTX 1070 and training immediately worked as expected.
@ayayaQ your experiement is make sense. We could be sure if we would have more example about this sitiuation. I also can add this example; I also try to make image classification by using tensorflow.keras and my training results are always wrong. When I predict on the model, results always return same index and same accuracy that is 1.
@iceisfun I think it is not about samples. Because when I train same dataset with same configuration in google colab, results make sense, everything is okay.
I think this could be an issue with the included version of cuDNN in PyTorch? I noticed one of the issues fixed in cuDNN release 8.2.2 stated as related to this GPU series.
NVIDIA Turing GTX 16xx users of cuDNN would observe invalid values in convolution output. This issue has been fixed in this release.
@ayayaQ Thanks for your research and sharing them with us. Latest version of PyTorch supports CUDA 10.2 and CUDA 11.1 but cuDNN 8.2.2 supports 10.2 and 11.4 so we have to use 10.2 version. I will try to do it and edit this answer.
@ayayaQ I tested your answer and problem is solved. I just changed cuda version from 11.1 to 10.2 and there is no problem. I used these codes.
pip3 install torch==1.9.1+cu102 torchvision==0.10.1+cu102 torchaudio===0.9.1 -f https://download.pytorch.org/whl/torch_stable.html
You can find same code at here
@MangoloD If you have not solved the problem yet, please try this way and notice us about your results.
Thanks for everyone.
I can confirm with the 10.2 installation that my training is now working as expected on the GTX 1660 Ti.
Hello Everybody, I have a similar problem hope you can help me. Training seems to be done:
Then I run the detection on a directory with one test image:
I do not seem to find any labels on the image I am testing!
@DaliaMahdy π Hello! Thanks for asking about improving YOLOv5 π training results.
Most of the time good results can be obtained with no changes to the models or training settings, provided your dataset is sufficiently large and well labelled. If at first you don't get good results, there are steps you might be able to take to improve, but we always recommend users first train with all default settings before considering any changes. This helps establish a performance baseline and spot areas for improvement.
If you have questions about your training results we recommend you provide the maximum amount of information possible if you expect a helpful response, including results plots (train losses, val losses, P, R, mAP), PR curve, confusion matrix, training mosaics, test results and dataset statistics images such as labels.png. All of these are located in your project/name
directory, typically yolov5/runs/train/exp
.
We've put together a full guide for users looking to get the best results on their YOLOv5 trainings below.
train_batch*.jpg
on train start to verify your labels appear correct, i.e. see example mosaic.Larger models like YOLOv5x and YOLOv5x6 will produce better results in nearly all cases, but have more parameters, require more CUDA memory to train, and are slower to run. For mobile deployments we recommend YOLOv5s/m, for cloud deployments we recommend YOLOv5l/x. See our README table for a full comparison of all models.
--weights
argument. Models download automatically from the latest YOLOv5 release.
python train.py --data custom.yaml --weights yolov5s.pt
yolov5m.pt
yolov5l.pt
yolov5x.pt
custom_pretrained.pt
--weights ''
argument:
python train.py --data custom.yaml --weights '' --cfg yolov5s.yaml
yolov5m.yaml
yolov5l.yaml
yolov5x.yaml
Before modifying anything, first train with default settings to establish a performance baseline. A full list of train.py settings can be found in the train.py argparser.
--img 640
, though due to the high amount of small objects in the dataset it can benefit from training at higher resolutions such as --img 1280
. If there are many small objects then custom datasets will benefit from training at native or higher resolution. Best inference results are obtained at the same --img
as the training was run at, i.e. if you train at --img 1280
you should also test and detect at --img 1280
.--batch-size
that your hardware allows for. Small batch sizes produce poor batchnorm statistics and should be avoided.hyp['obj']
will help reduce overfitting in those specific loss components. For an automated method of optimizing these hyperparameters, see our Hyperparameter Evolution Tutorial.If you'd like to know more a good place to start is Karpathy's 'Recipe for Training Neural Networks', which has great ideas for training that apply broadly across all ML domains: http://karpathy.github.io/2019/04/25/recipe/
Good luck π and let us know if you have any other questions!
@Elektrikci21 @DaliaMahdy I am facing the same problem. I was also training the model but the model unable to detect anything.
While training getting nan at box, obj, cls. What could be the reason?
Here is the result{graph}.
In training, it boxes some objects. But when I am testing the model unable to detect it. Model file saved as best.pt and last. pt both the model files are in PyTorch.
I can confirm with the 10.2 installation that my training is now working as expected on the GTX 1660 Ti.
Anyone manage to try using Cuda 11.3?
I realized I had a problem with the dataset from the roboflow side, it worked when I fixed it
@wtjasmine glad to hear that you were able to identify and fix the issue with your dataset. Dataset problems can often lead to unexpected results during training. Make sure to thoroughly review and validate your dataset to ensure it is well-labeled and representative of your target objects. If you encounter any further issues or have any additional questions, feel free to ask.
Hi, I haven't able to fix the issue, I have checked my dataset label, all objects are well labeled. I have followed all these recommendations on my dataset:
Images per class. β₯ 1500 images per class recommended
Instances per class. β₯ 10000 instances (labeled objects) per class recommended
Image variety. Must be representative of deployed environment. For real-world use cases we recommend images from different times of day, different seasons, different weather, different lighting, different angles, different sources (scraped online, collected locally, different cameras) etc.
Label consistency. All instances of all classes in all images must be labelled. Partial labelling will not work.
Label accuracy. Labels must closely enclose each object. No space should exist between an object and it's bounding box. No objects should be missing a label.
Label verification. View train_batch*.jpg on train start to verify your labels appear correct, i.e. see example mosaic.
Background images. Background images are images with no objects that are added to a dataset to reduce False Positives (FP). We recommend about 0-10% background images to help reduce FPs (COCO has 1000 background images for reference, 1% of the total). No labels are required for background images.
I have tried to train with 300 epochs without changing any default settings of the model, the training stops halfway after 100 epochs the metrics do not show improvement. Although the losses of both validation and training still decreasing during training, metrics like precision, recall, and mAP seems to stick around 0.53, does this means the training has reached the final results and training should stop? Because I am trying to detect small objects from images, could you pls suggest some tips to improve the results? Thank you.
@wtjasmine hi there,
I understand that you have followed the recommended guidelines for your dataset, ensuring sufficient images per class, instances per class, image variety, label consistency, label accuracy, label verification, and background images.
Regarding your training, if the losses are still decreasing but the metrics like precision, recall, and mAP appear to be stagnant around 0.53, it might indicate that the training has reached a plateau and further training might not lead to significant improvements. However, there are a few tips you can try to potentially improve the results for detecting small objects:
Adjust the model architecture: You can try modifying the YOLOv5 architecture to better handle small objects. Experiment with different backbone networks, feature pyramid networks, or anchor box configurations.
Increase the input image size: By increasing the image size, you provide more detailed information for the model to detect small objects. However, note that this may increase the computational requirements and training time.
Augment the dataset: Apply data augmentation techniques specifically aimed at enhancing small object detection, such as random scaling, translations, rotations, or adding noise. This can help the model generalize better to small objects.
Adjust the confidence threshold: You can experiment with different confidence thresholds during inference to find an optimal balance between recall and precision, particularly for small objects.
Fine-tune the hyperparameters: Explore different learning rates, weight decay values, or optimizer settings to find the best hyperparameters for your specific task.
Remember to monitor the training and validation metrics closely to evaluate the impact of these changes. Feel free to share any further questions or issues you may have. Good luck with your project!
I'm getting this error after training all the 100 epochs .. but the last step is not being completed. This error doesn't make my training 100% complete.
@vrushank41 the link you provided seems to be broken, and I'm unable to view the error image. Could you please double-check the link and ensure it is accessible to me? Additionally, if you could provide the error message or a description of the issue, I'd be more than happy to assist you further.
@vrushank41 It seems you're encountering an issue with a missing .csv file following the completion of the training process. Without being able to view the content from the provided links, it's challenging to identify the exact cause of the problem. However, it sounds like there might be an unexpected behavior at the end of the training process.
To better understand the issue, it would be helpful to have a bit more information:
Could you provide the specific error message or describe the missing .csv file in more detail? This will help in diagnosing and troubleshooting the problem.
Additionally, if you could share the specific steps you followed and the exact command used for training, it would provide context for understanding where the issue might have arisen.
Please feel free to provide additional details, and I'd be more than happy to help you resolve this issue.
If your metrics plateau, try increasing the image size or using a larger model like YOLOv5x. You can also experiment with data augmentation or hyperparameter tuning. For small objects, higher resolution images often help. Ensure your dataset is diverse and well-labeled.
Before submitting a bug report, please be aware that your issue must be reproducible with all of the following, otherwise it is non-actionable, and we can not help you:
git fetch && git status -uno
to check andgit pull
to update repoIf this is a custom dataset/training question you must include your
train*.jpg
,val*.jpg
andresults.png
figures, or we can not help you. You can generate these withutils.plot_results()
.π Bug
When I train coco128 dataset with yolov5, it trains and there is no warning about training. After training, yolov5 produce some folders and files such as weights, confusion_matrix.png, results.csv, results.png... When we look at results.png, confusion_matrix.png, result.csv they are just empty. You can see result.png below:
result.csv is same wiith resul.png as well. Some files is not created properly as I said but weights is created and they have same size with yolov5s.pt.
If I try to predict a sample with the trained model, it does not give me compatible result. There are no rectangles, error message, warning or something else but if I predict an image with yolov5s.pt which is produced by default, detection work. There is considirable result.
You can seee all processes below:
To Reproduce (REQUIRED)
To train a model
Input:
Output:
To detect
input:
output:
Here the output image
There are no labels, it is like input image.,
Expected behavior
A clear and concise description of what you expected to happen.
Environment
- OS:
Host Name: DESKTOP-3NBVRK6 OS Name: Microsoft Windows 10 Home OS Version: 10.0.19042 N/A Build 19042 OS Manufacturer: Microsoft Corporation OS Configuration: Standalone Workstation OS Build Type: Multiprocessor Free System Boot Time: 16.09.2021, 17:48:39 System Type: x64-based PC Processor(s): 1 Processor(s) Installed. 01: Intel64 Family 6 Model 165 Stepping 2 GenuineIntel ~2400 Mhz BIOS Version: INSYDE Corp. 1.07.10TFB5, 5.10.2020 Windows Directory: C:\Windows System Directory: C:\Windows\system32 Boot Device: \Device\HarddiskVolume1 System Locale: tr;Türkçe Input Locale: tr;Türkçe Time Zone: (UTC+03:00) İstanbul Total Physical Memory: 16.173 MB Available Physical Memory: 7.350 MB Virtual Memory: Max Size: 18.605 MB Virtual Memory: Available: 7.710 MB Virtual Memory: In Use: 10.895 MB Page File Location(s): C:\pagefile.sys Domain: WORKGROUP Hotfix(s): 10 Hotfix(s) Installed.
Hyper-V Requirements: VM Monitor Mode Extensions: Yes Virtualization Enabled In Firmware: Yes Second Level Address Translation: Yes Data Execution Prevention Available: Yes - GPU: Intel(R) UHD Graphics NVIDIA GeForce GTX 1650 Ti
DriverVersion 27.20.100.9365 30.0.14.7111
Python version: 3.9.7
If you have another files or informations, just let me know. Thanks.