Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better understanding of each parameter #6507

Closed
1 task done
Juanjojr9 opened this issue Feb 2, 2022 · 8 comments
Closed
1 task done

Better understanding of each parameter #6507

Juanjojr9 opened this issue Feb 2, 2022 · 8 comments
Labels
question Further information is requested

Comments

@Juanjojr9
Copy link

Search before asking

Question

Hello.

I tried to look for information about different parameters that can be used in train.py, val.py and detect.py, but I could not find information on some. I have tested activating each parameter, but I can't understand what they are for.
Is there an article explaining what each is for?

I would like to understand each of them as well as possible and make the most of them. I am very interested in this topic

I do not know what these parameters are used for, i.e. what their functions are, nor do I know when I should use them. Also I have other questions about some of them

In the train.py file:

  • What is --evolve for and how is it used?
  • --bucket
  • What is the logic of using --multi-scale, if the images change size when using --hyp? Since one hyperparameter is the scale: 0.5
  • --workers
  • --linear-lr
  • --local_rank
  • --label-smoothing
    Why if I put --nosave, it doesn't do the best.pt validation, nor does it do any metrics, like the PR curve?
  • --quad

In the val.py file:

  • --task (speed and study)
  • --augment
  • --half
  • --dnn

In the detect.py file:

  • --agnostic-nms
  • --update

I hope you can help me to solve this doubt.

Thank you very much for your help.

JJ

Additional

No response

@Juanjojr9 Juanjojr9 added the question Further information is requested label Feb 2, 2022
@glenn-jocher
Copy link
Member

glenn-jocher commented Feb 2, 2022

@Juanjojr9 we are working on improved documentation, but for the time being you can see the help field in each argument for details. If you have doubts about arguments, always use the default value.

yolov5/train.py

Lines 453 to 496 in 4c40933

def parse_opt(known=False):
parser = argparse.ArgumentParser()
parser.add_argument('--weights', type=str, default=ROOT / 'yolov5s.pt', help='initial weights path')
parser.add_argument('--cfg', type=str, default='', help='model.yaml path')
parser.add_argument('--data', type=str, default=ROOT / 'data/coco128.yaml', help='dataset.yaml path')
parser.add_argument('--hyp', type=str, default=ROOT / 'data/hyps/hyp.scratch.yaml', help='hyperparameters path')
parser.add_argument('--epochs', type=int, default=300)
parser.add_argument('--batch-size', type=int, default=16, help='total batch size for all GPUs, -1 for autobatch')
parser.add_argument('--imgsz', '--img', '--img-size', type=int, default=640, help='train, val image size (pixels)')
parser.add_argument('--rect', action='store_true', help='rectangular training')
parser.add_argument('--resume', nargs='?', const=True, default=False, help='resume most recent training')
parser.add_argument('--nosave', action='store_true', help='only save final checkpoint')
parser.add_argument('--noval', action='store_true', help='only validate final epoch')
parser.add_argument('--noautoanchor', action='store_true', help='disable AutoAnchor')
parser.add_argument('--evolve', type=int, nargs='?', const=300, help='evolve hyperparameters for x generations')
parser.add_argument('--bucket', type=str, default='', help='gsutil bucket')
parser.add_argument('--cache', type=str, nargs='?', const='ram', help='--cache images in "ram" (default) or "disk"')
parser.add_argument('--image-weights', action='store_true', help='use weighted image selection for training')
parser.add_argument('--device', default='', help='cuda device, i.e. 0 or 0,1,2,3 or cpu')
parser.add_argument('--multi-scale', action='store_true', help='vary img-size +/- 50%%')
parser.add_argument('--single-cls', action='store_true', help='train multi-class data as single-class')
parser.add_argument('--optimizer', type=str, choices=['SGD', 'Adam', 'AdamW'], default='SGD', help='optimizer')
parser.add_argument('--sync-bn', action='store_true', help='use SyncBatchNorm, only available in DDP mode')
parser.add_argument('--workers', type=int, default=8, help='max dataloader workers (per RANK in DDP mode)')
parser.add_argument('--project', default=ROOT / 'runs/train', help='save to project/name')
parser.add_argument('--name', default='exp', help='save to project/name')
parser.add_argument('--exist-ok', action='store_true', help='existing project/name ok, do not increment')
parser.add_argument('--quad', action='store_true', help='quad dataloader')
parser.add_argument('--linear-lr', action='store_true', help='linear LR')
parser.add_argument('--label-smoothing', type=float, default=0.0, help='Label smoothing epsilon')
parser.add_argument('--patience', type=int, default=100, help='EarlyStopping patience (epochs without improvement)')
parser.add_argument('--freeze', nargs='+', type=int, default=[0], help='Freeze layers: backbone=10, first3=0 1 2')
parser.add_argument('--save-period', type=int, default=-1, help='Save checkpoint every x epochs (disabled if < 1)')
parser.add_argument('--local_rank', type=int, default=-1, help='DDP parameter, do not modify')
# Weights & Biases arguments
parser.add_argument('--entity', default=None, help='W&B: Entity')
parser.add_argument('--upload_dataset', nargs='?', const=True, default=False, help='W&B: Upload data, "val" option')
parser.add_argument('--bbox_interval', type=int, default=-1, help='W&B: Set bounding-box image logging interval')
parser.add_argument('--artifact_alias', type=str, default='latest', help='W&B: Version of dataset artifact to use')
opt = parser.parse_known_args()[0] if known else parser.parse_args()
return opt

For --evolve see Hyperparameter Evolution tutorial below:

YOLOv5 Tutorials

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

@Juanjojr9
Copy link
Author

Hello @glenn-jocher,
First of all, I would like to thank you for your response.

Currently, I'm doing my final project for graduation using YOLOv5. That's why I'm so interested in learning as much as I can, and in case I am asked by my tutor, to be able to answer in a coherent manner.
I have read the help field in each argument, but it is not very detailed.

This is why I would like to know what each parameter does in a short form and I can defend myself

Any help is good.

JJ

@glenn-jocher
Copy link
Member

@Juanjojr9 thanks for your feedback! We will try to improve the documentation going forward to explain arguments in greater detail. For now the help section is all that is available, and as I said before if you are unsure of an argument then there is no reason to modify it.

@glenn-jocher
Copy link
Member

glenn-jocher commented Feb 2, 2022

@Juanjojr9 also I've added our tips for best training here which explain a few concepts.

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.
  • 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.

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

  • Start from Pretrained weights. Recommended for small to medium sized datasets (i.e. VOC, VisDrone, GlobalWheat). Pass the name of the model to the --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
  • Start from Scratch. Recommended for large datasets (i.e. COCO, Objects365, OIv6). Pass the model architecture yaml you are interested in, along with an empty --weights '' argument:
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 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.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.

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!

@Tautvydas-byte
Copy link

Hello, could you explain what is translate: 0.1 # image translation (+/- fraction) and perspective: 0.0 # image perspective (+/- fraction), range 0-0.001. Does image translate means something what is written in this article Image-to-Image Translation: Methods and Applications https://arxiv.org/pdf/2101.08629.pdf and image perspective is something like https://www.geeksforgeeks.org/perspective-transformation-python-opencv/ ?

@glenn-jocher
Copy link
Member

@Tautvydas-byte translation left-right or up-down

@Reynolddoss
Copy link

@glenn-jocher How would you suggest the retraining in the below case?
I have trained a model with 30 classes but I had the training data for just 25 classes.
Now I have the training data for 5 classes that were not included before. How can I retrain for this using the previously trained model? without using the previous data

@bit-scientist
Copy link

@Reynolddoss you must have your previous dataset whether you add or subtract from the first used dataset. You are dealing with the weights, they are updated in each iteration using gradient decent, so if you don't have a dataset of which you are planning to detect objects from, then there is no object in the first place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants