ultralytics / yolov5

YOLOv5 🚀 in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
50.41k stars 16.27k forks source link

Yolo with any number of channels #7825

Closed wouterio closed 2 years ago

wouterio commented 2 years ago

Search before asking

Description

Yolo now works with the three RGB color channels. Is it possible to make Yolo work with any number of channels?

Use case

For example, adding a 4th channel for pixel depth would enable Yolo to work with stereo vision. My guess is that this depth channel may contain a ton of information valuable for object detection (and perhaps also segmentation), because sudden differences in depth may indicate separate objects.

Another use case would be adding channels for hyperspectral data.

Additional

No response

Are you willing to submit a PR?

github-actions[bot] commented 2 years ago

👋 Hello @wouterio, thank you for your interest in YOLOv5 🚀! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution.

If this is a 🐛 Bug Report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset images, training logs, screenshots, and a public link to online W&B logging if available.

For business inquiries or professional support requests please visit https://ultralytics.com or email support@ultralytics.com.

Requirements

Python>=3.7.0 with all requirements.txt installed including PyTorch>=1.7. To get started:

git clone https://github.com/ultralytics/yolov5  # clone
cd yolov5
pip install -r requirements.txt  # install

Environments

YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

CI CPU testing

If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training (train.py), validation (val.py), inference (detect.py) and export (export.py) on macOS, Windows, and Ubuntu every 24 hours and on every commit.

wouterio commented 2 years ago

Had a better look at yolo.py and it seems that you can already choose the number of channels? Is that correct? If so, sorry for bothering... :)

glenn-jocher commented 2 years ago

@wouterio yes you can build YOLOv5 models with any number of input channels you want.

The dataloaders are not adapted for arbitrary channel dataloading currently though, so these would have to be modified, as well as some augmentations disabled (i.e. HSV) and plotting functions modified that display augmentations etc.

wouterio commented 2 years ago

Hi Glenn, Thanks for your response. How feasible is it to refactor the data loaders, augmentations, and plotting functions for any number of channels?

Let's take HSV augmentation as an example. I provide an ndarray image (width x height x channels) with channels Infrared, Red, Green, Blue, Ultraviolet, and Depth. And I provide a dict mapping the channels with the ndarray channel indices like {'IR':0, 'R':1, 'G':2, 'B':3, 'UV':4, 'D':5}. Then the HSV augmentation knows where to find the R, G, B channels in the ndarray. With such a mapping the HSV augmentation can be used on any number and order of channels, making it much more flexible.

My guess is that 3D will have quite an impact on object detection, because depth info makes it easier to distinguish objects from each other. Refactoring the yolo framework to allow any number of channels, would make working with 3D and other channels much easier. And that of course helps Ultralytics to stay ahead of the game.

glenn-jocher commented 2 years ago

@wouterio anything is possible with enough time and resources.

HSV augmentation would be skipped entirely if channels!=3. There are domains that simply don't correspond to RGB, i.e. CMYK, hyperspectral, infrared or other datasets.

wouterio commented 2 years ago

Haha yes time and resources always seem to make a difference in programming. 😆

Yes I understand HSV augmentation is not applicable to all domains. But if you have a set of channels containing at least R and G and B, then you can perform HSV augmentation on those 3 channels and leave the other channels as they were.

The HSV augmentation was just an example anyway. It's more that this mapping between channels and ndarray channel indices would make your framework super flexible.

With some smart design it's even possible to keep the framework's public interface backwards compatible:

DEFAULT_CHANNEL_MAPPING = {'R':0, 'G':1, 'B':2}

def some_fun(arr, ... other args ..., channel_mapping = None): channel_mapping = channel_mapping or DEFAULT_CHANNEL_MAPPING

do stuff

For RGB all functions remain the same, for other channels you need to specify the mapping. But yeah, it's all up to you whether you find this interesting or not.

github-actions[bot] commented 2 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 ⭐!

glenn-jocher commented 11 months ago

@wouterio I appreciate your thoughtful insights. Our team will take your input into consideration as we continue to evolve and improve the YOLOv5 framework. We are committed to making our framework as versatile and user-friendly as possible. Thank you for taking the time to share your ideas with us.