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

comment missing arg #1135

Closed
wants to merge 1 commit into from
Closed

comment missing arg #1135

wants to merge 1 commit into from

Conversation

Borda
Copy link
Contributor

@Borda Borda commented Oct 13, 2020

the case is that with this call:

python train.py \
  --img-size 608 \
  --epochs 40 \
  --single-cls \
  --cfg ./models/${model}.yaml \
  --weights ./weights/${model}.pt \
  --logdir /data/logs/${model} \
  --data ./data/my-data.yaml \
  --evolve

I get following error:

Namespace(adam=False, batch_size=56, bucket='', cache_images=False, cfg='./models/yolov5s.yaml', data='./data/shops_pd2-3.yaml', device='0', epochs=40, evolve=True, global_rank=-1, hyp='data/hyp.scratch.yaml', image_weights=False, img_size=[608, 608], local_rank=-1, logdir='/data/Project_Video/RESULTS/Yolo-v5/shops-ppl_yolov5s', multi_scale=False, name='pd2-3_evolve', noautoanchor=False, nosave=False, notest=False, rect=False, resume=False, single_cls=True, sync_bn=False, total_batch_size=56, weights='./weights/yolov5s.pt', workers=28, world_size=1)
  0%|                                                                                                                                                                                                                 | 0/150 [00:00<?, ?it/s]
Traceback (most recent call last):
  File "train.py", line 524, in <module>
    hyp[k] = max(hyp[k], v[1])  # lower limit
KeyError: 'anchors'

🛠️ PR Summary

Made with ❤️ by Ultralytics Actions

🌟 Summary

Enhanced hyperparameter flexibility in YOLOv5 training.

📊 Key Changes

  • The 'anchors' hyperparameter line in the training script has been commented out.

🎯 Purpose & Impact

  • 🛠 Purpose: The change appears to simplify the hyperparameter space by removing an option that could be left at its default or was potentially unused or unnecessary. This can make the training process more straightforward.
  • 🚀 Impact: Users might experience a more streamlined hyperparameter set, possibly improving ease of use by reducing the number of hyperparameters they need to consider when configuring their training runs. The change might also indicate a shift towards more automated or internally managed anchor settings that require less manual tuning.

@Borda
Copy link
Contributor Author

Borda commented Oct 13, 2020

@glenn-jocher or am I doing something wrong?

@glenn-jocher
Copy link
Member

glenn-jocher commented Oct 13, 2020

Hmmm good question. The anchors field in the hyps dictionary will force an autoanchor calculation. This is really useful during evolution to let the anchor count evolve, but not desired during normal training, which is why they are commented by default.

When I evolved before I uncommented the anchor field, and gave it a nonzero starting value, i.e anchors: 3 to start from the default anchor count of 3 per layer. I regret the complication, there must be a better way, but can't think of it at the moment.

@glenn-jocher
Copy link
Member

I think commenting the same field in the meta dictionary can work... yes that should work, it will act as if the field does not exist at all. Anchor count will be fixed at 3, and autoanchor will be run if the Best Possible Recall (BPR) dips below threshold, which is set at 0.98 at the moment. Varying the hyps can cause your BPR to vary, so its possible some generations may use it and other not.

@Borda Borda closed this Oct 13, 2020
@Borda Borda deleted the evolve/args branch October 13, 2020 21:06
@glenn-jocher
Copy link
Member

glenn-jocher commented Oct 13, 2020

EDIT: BTW the reason there are two dictionaries is that the meta dictionary contains gains and bounds applied to each hyperparameter during evolution as key: [gain, lower_bound, upper_bound]. meta is only ever used during evolution, I kept it separated to avoid complicating the hyp dictionary, again not sure if that's the best design choice, we could merge them, but then each hyp.yaml would be busier and more complicated to read.

@Borda
Copy link
Contributor Author

Borda commented Oct 19, 2020

When I evolved before I uncommented the anchor field, and gave it a nonzero starting value, i.e anchors: 3 to start from the default anchor count of 3 per layer. I regret the complication, there must be a better way, but can't think of it at the moment.

where shall I add this option, because the evolve is still failing for me unless I comment it...
when I add it to hyper yaml file I get following error:

Traceback (most recent call last):
  File "train.py", line 525, in <module>
    hyp[k] = float(x[i + 7] * v[i])  # mutate
IndexError: index 34 is out of bounds for axis 0 with size 34

@glenn-jocher
Copy link
Member

glenn-jocher commented Oct 20, 2020

@Borda to evolve the number of anchors your model uses, you can uncomment the anchors: 0 line in your hyp.scratch.yaml, or any other hyp.yaml you are using. You set it to a nonzero value, like anchors: 5 to start from 5, and then run your evolve command.

OR if you want to leave your anchor count alone, just comment anchors in both places: the meta dictionary on train.py L479 and in your hyp.yaml

Screenshot 2020-10-20 at 15 15 33

@glenn-jocher
Copy link
Member

glenn-jocher commented Jul 5, 2021

@Borda good news 😃! Your original issue may now be fixed ✅ in PR #3887. This PR adds hyp['anchors']=3 if the anchors key is missing/commented in your hyperparameter file, fixing a long-running problem when starting hyp evolution using the default command:

python train.py --evolve

To receive this update:

  • Gitgit pull from within your yolov5/ directory or git clone https://github.com/ultralytics/yolov5 again
  • PyTorch Hub – Force-reload with model = torch.hub.load('ultralytics/yolov5', 'yolov5s', force_reload=True)
  • Notebooks – View updated notebooks Open In Colab Open In Kaggle
  • Dockersudo docker pull ultralytics/yolov5:latest to update your image Docker Pulls

Thank you for spotting this issue and informing us of the problem. Please let us know if this update resolves the issue for you, and feel free to inform us of any other issues you discover or feature requests that come to mind. Happy trainings with YOLOv5 🚀!

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

Successfully merging this pull request may close these issues.

2 participants