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

Passing input channels to Model constructor instead of hardcoding the value #12382

Closed
wants to merge 5 commits into from

Conversation

jere357
Copy link

@jere357 jere357 commented Nov 15, 2023

Passing number of channels in input as a part of the config (defaults back to 3) when creating the Model object in train.py
I was working on a yolo model that will take as input images that are not necessarily RGB - and while coding around i noticed that you hardcode the value of number of input channels.
I think it is better practice/prettier code if you define the number of input channels in a .yaml file and then load that value while creating the model. The way i do it in this PR is that i define input_channels: 3 in the hyperparameter file.

An alternative method could be that you detect the number of channels in the dataset, but i think that might be a bit overkill/inconsistent.

I am interested in hearing your opinions/suggestions about improving this method of defining the numbers of channels in a .yaml

thanks to @akx for suggesting defaulting number of channels to 3 for backwards compatibility in the first PR

πŸ€–[deprecated] Generated by Copilot at 0acac83

Summary

πŸŽ›οΈπŸŒˆπŸš€

This pull request adds a new parameter input_channels to the YAML files of the YOLOv5 models, which allows the user to customize the number of input channels for different types of data. It also modifies the train function in train.py to use the value of input_channels from the YAML files instead of a hard-coded value.

Sing, O Muse, of the skillful code review
That added a new parameter to the YAML files
Of the swift and powerful YOLOv5 models
That detect objects with keen eyes and many channels

Walkthrough

  • Add input_channels parameter to YAML files of YOLOv5 models, which allows the user to customize the number of input channels for different types of data (link, link, link, link)
  • Modify train function in train.py to use input_channels value from hyp dictionary instead of hard-coded 3, and add default value of 3 in case the key is not present. This makes the function compatible with the new parameter and enables training with different input channels (link, link)

πŸ› οΈ PR Summary

Made with ❀️ by Ultralytics Actions

πŸ“Š Key Changes

  • Added a new configuration parameter input_channels in various YOLOv5 model configuration files (yolov5s.yaml, yolov5m.yaml, yolov5l.yaml, yolov5n.yaml).
  • Updated the train.py script to use the input_channels parameter from hyperparameters (hyp) instead of hardcoding it to 3.

🎯 Purpose & Impact

  • The purpose is to make the number of input channels configurable, allowing the model to support different types of input (e.g., grayscale images, which have only 1 channel, or multispectral images with more than 3 channels). πŸ› οΈ
  • This change increases flexibility and makes YOLOv5 more adaptable to various computer vision tasks with inputs beyond the standard RGB images. 🌈

🌟 Summary

Enabled dynamic configuration of input channels in YOLOv5 for greater flexibility in handling images with different numbers of channels. πŸ”„

Copy link
Contributor

πŸ‘‹ Hello there! We wanted to let you know that we've decided to close this pull request due to inactivity. We appreciate the effort you put into contributing to our project, but unfortunately, not all contributions are suitable or aligned with our product roadmap.

We hope you understand our decision, and please don't let it discourage you from contributing to open source projects in the future. We value all of our community members and their contributions, and we encourage you to keep exploring new projects and ways to get involved.

For additional resources and information, please see the links below:

Thank you for your contributions to YOLO πŸš€ and Vision AI ⭐

@github-actions github-actions bot added the Stale label Apr 18, 2024
@github-actions github-actions bot closed this May 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant