ultralytics / yolov5

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

Does augmentation (such as flipud, fliplr, resize) be considered in anchor generation process ? #1901

Closed daikankan closed 3 years ago

daikankan commented 3 years ago

❔Question

Additional context

github-actions[bot] commented 3 years ago

👋 Hello @daikankan, 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://www.ultralytics.com or email Glenn Jocher at glenn.jocher@ultralytics.com.

Requirements

Python 3.8 or later with all requirements.txt dependencies installed, including torch>=1.7. To install run:

$ pip install -r requirements.txt

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), testing (test.py), inference (detect.py) and export (export.py) on MacOS, Windows, and Ubuntu every 24 hours and on every commit.

glenn-jocher commented 3 years ago

@daikankan no, the augmentation policy is not executed on labels loaded for autoanchor. Label augmentation is intrinsically tied to image augmentation in random_perspective(), they are thus inseparable in the current dataloader. In any case its unclear if we would want to evolve anchors on augmented labels, as our metric is mAP on the (unaugmented) validation set.

In your example flipud and fliplr will naturally have zero effect on anchor shapes, but scale will. Scale can be manually approximated by uncommenting this line: https://github.com/ultralytics/yolov5/blob/1d1c0567a415941c109d1a2bf1a10ffde319f937/utils/autoanchor.py#L116

jaqub-manuel commented 3 years ago

Dear @glenn-jocher

Yo said thatt Flipud and fliplr effect is 0.

So what data augmentation techniques have an effect on autoanchor? For example, autoanchor is not calculated in methods such as sclae, shear, mosaic and mixup? Autoanchor has no effect on values like rotation, hsv, flip, saturation only?

If so, wouldn't it make more sense to find new anchor values using properties like scale and shear using the autoanchor method? Then, training is started with the normal training set.

glenn-jocher commented 3 years ago

@jaqub-manuel this is more of a research oriented question. I'd suspect you would want anchors aligned with the image-space you want to deploy to, which may or may not include augmentation effects depending on your domain and use case etc. Feel free to experiment.

abhiagwl4262 commented 3 years ago

@glenn-jocher Before calculating anchors, you are changing width and height as per the required image dimension (imgsz) using following line of code. https://github.com/ultralytics/yolov5/blob/1d1c0567a415941c109d1a2bf1a10ffde319f937/utils/autoanchor.py#L108

That means anchors are being calculated on resized images

glenn-jocher commented 3 years ago

@abhiagwl4262 yes anchors are defined as a function of training image sizes.

leeyunhome commented 3 years ago

@abhiagwl4262 yes anchors are defined as a function of training image sizes.

Hello,

Is it not necessary to manually calculate the anchor box when training with a custom dataset?

Thank you.

abhiagwl4262 commented 3 years ago

@leeyunhome Custom Anchors always seems to be giving better results

glenn-jocher commented 3 years ago

@leeyunhome autoanchor will evolve new anchors custom suited to your dataset and training parameters if your existing anchors are deemed to be poor fits to your data. No action is required on your part, this is all part of the default YOLOv5 training workflow.

leeyunhome commented 3 years ago

@leeyunhome autoanchor will evolve new anchors custom suited to your dataset and training parameters if your existing anchors are deemed to be poor fits to your data. No action is required on your part, this is all part of the default YOLOv5 training workflow.

Are you saying it has nothing to do with inferencing accuracy?

Thank you.

glenn-jocher commented 3 years ago

@leeyunhome no I'm not saying that. Anchors are important for good accuracy.

github-actions[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.