You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have searched the YOLOv5 issues and discussions and found no similar questions.
Question
Recently I'm working on something with yolo, and I have developed my own model and train it in this framework. When I tried to prune my model, I found that because of the particularity of the framework, everytime you need to train a model, you have to first have a yaml file telling the detailed structures of the network. Since pruned models have different channels, I have to modify the yaml file manually as discussed in this issue. So I'm now trying to design a script to automatically modify the yaml file for the network, though it can only be used for my network. I have tried a lot and failed to dump the correct format that looks same with original yaml format. Here is my code:
👋 Hello @tobymuller233, thank you for your interest in YOLOv5 🚀! It sounds like you're diving deep into modifying the YAML configuration for custom network architectures and pruning.
If this is a 🐛 Bug Report, please ensure you include a minimum reproducible example to help us assist you more effectively.
For custom YAML modification ❓ Questions, please provide details about your dataset and training process, and make sure you’ve followed best practices. It's fantastic that you're working on automating this process; remember that ruamel.yaml can be very handy for preserving YAML structure while editing.
Requirements
Ensure you are using Python>=3.8.0 with all dependencies from requirements.txt installed, including PyTorch>=1.8.
Environments
YOLOv5 can run in various environments with the necessary dependencies installed like Notebooks with GPU support, Google Cloud, AWS, and Docker containers.
Status
If you encounter issues with YAML formatting, note the indentations and flow styles of the YAML libraries you are using. This can affect how nested lists are displayed, as you've observed.
This is an automated response, and an Ultralytics engineer will be with you shortly to provide further assistance. Thank you for your patience and for sharing your work with us! 😊
To generate a YOLO-style YAML file with specific formatting, you can use the ruamel.yaml library, which allows for more control over how lists and other structures are formatted. In your script, ensure you set the flow style correctly for nested lists. Here's a refined approach to achieve your desired format:
fromruamel.yamlimportYAMLfromruamel.yaml.commentsimportCommentedSeqdefmake_compact_list(data):
result=CommentedSeq(data)
result.fa.set_flow_style() # Set flow style for inline list representationreturnresult# ... (rest of your existing code)yaml_save=YAML()
yaml_save.default_flow_style=None# Ensures proper inline formattingyaml_save.indent(sequence=4, offset=2) # Adjust indentationwithopen("pruned_model.yaml", "w") asf:
yaml_save.dump(model_dict, f)
Make sure to apply make_compact_list to both backbone and head lists within your parse_model function. This should help in maintaining the inline format you are aiming for. If further issues persist, consider checking if ruamel.yaml is appropriately handling nested structures as expected.
Search before asking
Question
Recently I'm working on something with yolo, and I have developed my own model and train it in this framework. When I tried to prune my model, I found that because of the particularity of the framework, everytime you need to train a model, you have to first have a yaml file telling the detailed structures of the network. Since pruned models have different channels, I have to modify the yaml file manually as discussed in this issue. So I'm now trying to design a script to automatically modify the yaml file for the network, though it can only be used for my network. I have tried a lot and failed to dump the correct format that looks same with original yaml format. Here is my code:
Here shows what it looks like:
And I just want the members of
backbone
andhead
be in a single row just like this:FYI, the reason for why I used
ruamel.yaml
instead ofyaml
is that I triedyaml
before using:But it turns out that this only fits
anchors
since there is only one layer of embedded list instead of two.:Additional
No response
The text was updated successfully, but these errors were encountered: