ultralytics / yolov5

YOLOv5 πŸš€ in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
51.24k stars 16.44k forks source link

Where new anchor .yaml save in folder? #4301

Closed ghost closed 3 years ago

ghost commented 3 years ago

❔Question

I have trained the model using the following command

!python train.py --imgsz 2000 --batch 2 --epochs 150 --data '/content/yolov5/data/coco.yaml' --cfg ./models/yolov5m.yaml --weights '' 
## Additional context
autoanchor: Analyzing anchors... anchors/target = 0.09, Best Possible Recall (BPR) = 0.0882. Attempting to improve anchors, please wait...
autoanchor: WARNING: Extremely small objects found. 2598879 of 2794845 labels are < 3 pixels in size.
autoanchor: Running kmeans for 9 anchors on 1908600 points...
autoanchor: thr=0.25: 0.9997 best possible recall, 8.91 anchors past thr
autoanchor: n=9, img_size=2016, metric_all=0.618/0.841-mean/best, past_thr=0.623-mean: 2,2,  2,2,  2,2,  2,3,  3,2,  3,2,  3,3,  3,4,  4,4
autoanchor: Evolving anchors with Genetic Algorithm:: 100% 1000/1000 [10:36<00:00,  1.57it/s]
autoanchor: thr=0.25: 0.9997 best possible recall, 8.91 anchors past thr
autoanchor: n=9, img_size=2016, metric_all=0.618/0.841-mean/best, past_thr=0.623-mean: 2,2,  2,2,  2,2,  2,3,  3,2,  3,2,  3,3,  3,4,  4,4
autoanchor: New anchors saved to model. Update model *.yaml to use these anchors in the future.

Where is the new anchor file is saved to train the model again? I have an image size of 4800x2728 with greater number of labels in image

glenn-jocher commented 3 years ago

@hammadyounas2008 πŸ‘‹ Hello! Thanks for asking about model anchors. YOLOv5 πŸš€ uses a new Ultralytics algorithm called autoanchor for anchor verification and generation before training starts.

Autoanchor will analyse your anchors against your dataset and training settings (like --img-size), and will adjust your anchors as necessary if it determines the original anchors are a poor fit, or if an anchor count was specified in your model.yaml rather than anchor values, i.e.

# Specify anchor count (per layer)
anchors: 3

# --OR-- Specify anchor values manually
anchors:
  - [10,13, 16,30, 33,23]  # P3/8
  - [30,61, 62,45, 59,119]  # P4/16
  - [116,90, 156,198, 373,326]  # P5/32

When generating new anchors, autoanchor first applies a kmeans function against your dataset labels (scaled to your training --img-size), and then uses these kmeans centroids as initial conditions for a Genetic Evolution (GE) algorithm. The GE algorithm will evolve all anchors for 1000 generations under default settings, using the CIoU loss (same one used during training) combined with Best Possible Recall (BPR) as its fitness function.

No action is required on your part to use autoanchor. If you would like to force manual anchors for any reason, you can skip autoanchor with the --noautoanchor flag:

python train.py --noautoanchor
ghost commented 3 years ago

Thanks for your reply, It automatically changes the anchor in the model or do I have to manually place the value? My validation error is still 0

glenn-jocher commented 3 years ago

@hammadyounas2008 I believe https://github.com/ultralytics/yolov5/issues/4301#issuecomment-892556355 addresses your question.

Zero validation error is quite impressive.

ghost commented 3 years ago

Sorry Precision and recall of validation is still 0, I am just asking did I have to update the anchor manually or it will work automatically to update the .yaml file? Like this images rd

AnranXu commented 3 years ago

Can we output the result of the autoanchor?

glenn-jocher commented 3 years ago

@AnranXu autoanchor already outputs results to console.

fcakyon commented 3 years ago

@glenn-jocher what is the default anchor number?

glenn-jocher commented 3 years ago

@fcakyon πŸ‘‹ Hello! Thanks for asking about model anchors. Default anchor count is 3 per output layer.

YOLOv5 πŸš€ uses a new Ultralytics algorithm called autoanchor for anchor verification and generation before training starts.

Autoanchor will analyse your anchors against your dataset and training settings (like --img-size), and will adjust your anchors as necessary if it determines the original anchors are a poor fit, or if an anchor count was specified in your model.yaml rather than anchor values, i.e.

# Specify anchor count (per layer)
anchors: 3

# --OR-- Specify anchor values manually
anchors:
  - [10,13, 16,30, 33,23]  # P3/8
  - [30,61, 62,45, 59,119]  # P4/16
  - [116,90, 156,198, 373,326]  # P5/32

When generating new anchors, autoanchor first applies a kmeans function against your dataset labels (scaled to your training --img-size), and then uses these kmeans centroids as initial conditions for a Genetic Evolution (GE) algorithm. The GE algorithm will evolve all anchors for 1000 generations under default settings, using the CIoU loss (same one used during training) combined with Best Possible Recall (BPR) as its fitness function.

No action is required on your part to use autoanchor. If you would like to force manual anchors for any reason, you can skip autoanchor with the --noautoanchor flag:

python train.py --noautoanchor
github-actions[bot] commented 3 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 ⭐!