ultralytics / yolov5

YOLOv5 🚀 in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
50.02k stars 16.17k forks source link

image augmented but not annotations #8022

Closed siddhantoon closed 2 years ago

siddhantoon commented 2 years ago

Search before asking

YOLOv5 Component

Training

Bug

I am trying to do object detection in densely packed scenario, similar to SKU110K dataset. After the training is finished the runs/train/ directory has images of train_batch val_batch that are ground truth annotated images. hyp.scratch.yaml file has scale:0.5 and translate:0.1 These are the images I found there:

  1. As you can see only images are translated or scaled, no change to bounding box. 2.BBox are at their original position but images are shifted. image image

Environment

No response

Minimal Reproducible Example

No response

Additional

No response

Are you willing to submit a PR?

github-actions[bot] commented 2 years ago

👋 Hello @siddhantoon, 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 support@ultralytics.com.

Requirements

Python>=3.7.0 with all requirements.txt installed including PyTorch>=1.7. 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

CI CPU testing

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 commented 2 years ago

@siddhantoon 👋 Hello! Thanks for asking about image augmentation. YOLOv5 🚀 applies online imagespace and colorspace augmentations in the trainloader (but not the val_loader) to present a new and unique augmented Mosaic (original image + 3 random images) each time an image is loaded for training. Images are never presented twice in the same way.

YOLOv5 augmentation

Augmentation Hyperparameters

The hyperparameters used to define these augmentations are in your hyperparameter file (default data/hyp.scratch.yaml) defined when training:

python train.py --hyp hyp.scratch-low.yaml

https://github.com/ultralytics/yolov5/blob/b94b59e199047aa8bf2cdd4401ae9f5f42b929e6/data/hyps/hyp.scratch-low.yaml#L6-L34

Augmentation Previews

You can view the effect of your augmentation policy in your train_batch*.jpg images once training starts. These images will be in your train logging directory, typically yolov5/runs/train/exp:

train_batch0.jpg shows train batch 0 mosaics and labels:

YOLOv5 Albumentations Integration

YOLOv5 🚀 is now fully integrated with Albumentations, a popular open-source image augmentation package. Now you can train the world's best Vision AI models even better with custom Albumentations 😃!

PR https://github.com/ultralytics/yolov5/pull/3882 implements this integration, which will automatically apply Albumentations transforms during YOLOv5 training if albumentations>=1.0.3 is installed in your environment. See https://github.com/ultralytics/yolov5/pull/3882 for full details.

Example train_batch0.jpg on COCO128 dataset with Blur, MedianBlur and ToGray. See the YOLOv5 Notebooks to reproduce: Open In Colab Open In Kaggle

Good luck 🍀 and let us know if you have any other questions!

siddhantoon commented 2 years ago

Hey @glenn-jocher, in my hyp.scratch.yaml scale is 0.5 and transate is 0.1, and in train_batch*.jpg images the images are scaled and translated but augmentations are not, if you see in the image I posted bounding box are shifted

glenn-jocher commented 2 years ago

@siddhantoon user error due to incorrect labels. To train correctly your data must be in YOLOv5 format. Please see our Train Custom Data tutorial for full documentation on dataset setup and all steps required to start training your first model. A few excerpts from the tutorial:

1.1 Create dataset.yaml

COCO128 is an example small tutorial dataset composed of the first 128 images in COCO train2017. These same 128 images are used for both training and validation to verify our training pipeline is capable of overfitting. data/coco128.yaml, shown below, is the dataset config file that defines 1) the dataset root directory path and relative paths to train / val / test image directories (or *.txt files with image paths), 2) the number of classes nc and 3) a list of class names:

# Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
path: ../datasets/coco128  # dataset root dir
train: images/train2017  # train images (relative to 'path') 128 images
val: images/train2017  # val images (relative to 'path') 128 images
test:  # test images (optional)

# Classes
nc: 80  # number of classes
names: [ 'person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 'truck', 'boat', 'traffic light',
         'fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow',
         'elephant', 'bear', 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee',
         'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', 'baseball glove', 'skateboard', 'surfboard',
         'tennis racket', 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple',
         'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch',
         'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote', 'keyboard', 'cell phone',
         'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors', 'teddy bear',
         'hair drier', 'toothbrush' ]  # class names

1.2 Create Labels

After using a tool like Roboflow Annotate to label your images, export your labels to YOLO format, with one *.txt file per image (if no objects in image, no *.txt file is required). The *.txt file specifications are:

Image Labels

The label file corresponding to the above image contains 2 persons (class 0) and a tie (class 27):

1.3 Organize Directories

Organize your train and val images and labels according to the example below. YOLOv5 assumes /coco128 is inside a /datasets directory next to the /yolov5 directory. YOLOv5 locates labels automatically for each image by replacing the last instance of /images/ in each image path with /labels/. For example:

../datasets/coco128/images/im0.jpg  # image
../datasets/coco128/labels/im0.txt  # label

Good luck 🍀 and let us know if you have any other questions!

github-actions[bot] commented 2 years ago

👋 Hello, this issue has been automatically marked as stale because it has not had recent activity. Please note it will be closed if no further activity occurs.

Access additional YOLOv5 🚀 resources:

Access additional Ultralytics ⚡ resources:

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 YOLOv5 🚀 and Vision AI ⭐!

alkhalisy commented 2 years ago

Dear Glenn Jocher, How are you?

Pls I trying to create A new custom dataset that has 4 classes every class has 1200 color images, and the class names eye_movment, move_hand, looking_side, and mobile_use as student behavioral analysis for the online exam. For the training result mentioned below, I used the yolov5s with default values. The testing results with poor accuracy 0.2 or 0.4 in this range, I tested the model with input frames from the webcam in real time, please can you help me by that what you suggestions to fix this problem or where the problem exactly, I notice the model trained in just 4 epochs and I think is it not normal because I try to train with more than 4 epoch like 10 or 50 the result become worst I thing overfitting. please how can I solve the problem? or what kind of problem I have, Please help me confusion_matrix labels F1_curve PR_curve

labels_correlogram

labels val_batch2_pred val_batch1_labels val_batch1_pred

![train_batch2](https://user-imag val_batch2_labels

val_batch0_pred es.githu val_batch0_labels busercontent.com/49120272/190858683-f005facc-08dc-4420-ade7-17e0c7b3cbdb.jpg)


some test results from 10% of the dataset these images not in training set

Senario_12 083

Senario_12 083 t_5 353 12 0009 g 084 g_5 375 g_8 006 m_8 012 m_scenario_8 215 m_Senario_2 447 ms_Senario_5 552 satu-1 366 jpg

when I try to test the model in real time where I captured the frames from the webcam the detection result is very bad 0.2 or 0.3 no more and also different from one class to another, for example, the eye_movment was very bad accuracy ?? I try to use yolov5n6 but the result still not good can you help me

glenn-jocher commented 2 years ago

@alkhalisy 👋 Hello! Thanks for asking about improving YOLOv5 🚀 training results. Your training data must share a common image space with your deployment environment for best results, otherwise your model will not generalize well to the real world:

dataset

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.

Dataset

COCO Analysis

Model Selection

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.

YOLOv5 Models

Training Settings

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.

Further Reading

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!

alkhalisy commented 2 years ago

Dear Glenn Jocher thank you very much for clearing your suggested solution. 1- is there any other solution? because as I mentioned before this dataset should be used on online exam apps and in this scenario no fixed deployment environment like any house for any student. in this case how yolo model can detect any person any book any 80 objects in any environment?? 2- I try before to remove all background from all images in the dataset by segmentation techniques. the result images just with person's actions no bg, I thought in this manner make the model focus in the person nor the environment but really the results still poor. 3- if I use grayscale images not RGB or less color depth images in the dataset, is this may improve accuracy? 4- why training the model just for 4 epochs is the best result while more epoch decrease accuracy in the real world? 5- from the Training analytical data was sent (CM, P,R, MaP) any evidence for overfitting? many thanks

Muhanad Abdul Elah Alkhalisy *MSc Software Engineering University of Information Technology and Communications Mobile: +96407718662757 Email: @.

On Sat, Sep 17, 2022 at 9:07 PM Glenn Jocher @.***> wrote:

@alkhalisy https://github.com/alkhalisy 👋 Hello! Thanks for asking about improving YOLOv5 🚀 training results. Your training data must share a common image space with your deployment environment for best results, otherwise your model will not generalize well to the real world:

[image: dataset] https://user-images.githubusercontent.com/26833433/190870656-a331679f-b60e-4813-9263-597c1731c3e3.png

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. 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 https://docs.ultralytics.com/yolov5/tutorials/train_custom_data#local-logging 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.

[image: COCO Analysis] https://arxiv.org/abs/1405.0312 Model Selection

Larger models like YOLOv5x and YOLOv5x6 https://github.com/ultralytics/yolov5/releases/tag/v5.0 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 https://github.com/ultralytics/yolov5#pretrained-checkpoints for a full comparison of all models.

[image: YOLOv5 Models] https://github.com/ultralytics/yolov5/releases/download/v1.0/model_comparison.png

python train.py --data custom.yaml --weights yolov5s.pt

                                         yolov5m.pt

                                         yolov5l.pt

                                         yolov5x.pt

                                         custom_pretrained.pt

python train.py --data custom.yaml --weights '' --cfg yolov5s.yaml

                                                  yolov5m.yaml

                                                  yolov5l.yaml

                                                  yolov5x.yaml

Training Settings

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 https://github.com/ultralytics/yolov5/blob/master/train.py argparser.

  • Epochs. Start with 300 epochs. If this overfits early then you can reduce epochs. If overfitting does not occur after 300 epochs, train longer, i.e. 600, 1200 etc epochs.
  • Image size. COCO trains at native resolution of --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. Use the largest --batch-size that your hardware allows for. Small batch sizes produce poor batchnorm statistics and should be avoided.
  • Hyperparameters. Default hyperparameters are in hyp.scratch-low.yaml https://github.com/ultralytics/yolov5/blob/master/data/hyps/hyp.scratch-low.yaml. We recommend you train with default hyperparameters first before thinking of modifying any. In general, increasing augmentation hyperparameters will reduce and delay overfitting, allowing for longer trainings and higher final mAP. Reduction in loss component gain hyperparameters like hyp['obj'] will help reduce overfitting in those specific loss components. For an automated method of optimizing these hyperparameters, see our Hyperparameter Evolution Tutorial https://docs.ultralytics.com/yolov5/tutorials/hyperparameter_evolution.

Further Reading

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!

— Reply to this email directly, view it on GitHub https://github.com/ultralytics/yolov5/issues/8022#issuecomment-1250116621, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALWYIEFZATXHHOAUBWKF553V6YCG5ANCNFSM5XGVUSRA . You are receiving this because you were mentioned.Message ID: @.***>