Vision: No support for multi-channel images

Created on 2 May 2019  路  8Comments  路  Source: pytorch/vision

Multi-channel images are common in the fields of satellite remote sensing (GIS) and in medical imaging. Many of the multispectral satellites I work with in my research have 8+ spectral bands, not just RGB. Some hyperspectral satellites have as many as 136 spectral bands. Microscopy often involves 4+ channel images as well.

Currently, torchvision relies on the Python Imaging Library (PIL) for all of its transforms. Unfortunately, pillow does not support multi-channel images: https://github.com/python-pillow/Pillow/issues/3160, https://github.com/python-pillow/Pillow/issues/1888

The way I see it, researchers such as myself have 3 options:

  1. Fix PIL (unlikely, as https://github.com/python-pillow/Pillow/issues/1888 has been stalled for 3 years now)
  2. Fix torchvision (this would involve implementing all of the current transforms by hand using torch Tensors or numpy arrays)
  3. Fork torchvision (write all of the transforms we need ourselves)

I'm about to resort to 3 for my research. Do you have any suggestions for users like me?

Most helpful comment

By the way, in https://github.com/pytorch/vision/pull/1104 we are slowly going to be starting to support PyTorch Tensors for some of the transforms natively in torchvision, so that this won't be an issue anymore

All 8 comments

I agree that is indeed a common problem in remote sensing, especially hyperspectral imaging.

This is an ongoing discussion (although for some other reasons), which leans to option 2. Recently @fmassa stated:

[...] I'd rather not rush things just yet

Thus, if I were you, I would go with option 3. for now, but check back regularly for official support.

I would love for this to be a focus. Not only is it a problem for multi-channel data, but also it causes issue for target transformations for semantic segmentation where a channel is needed for each target.

@jphdotam we are going to be following a slightly different approach for semantic segmentation, where we will be using torch operations to perform the transformations.

See https://github.com/pytorch/vision/blob/master/references/segmentation/transforms.py for an example

By the way, in https://github.com/pytorch/vision/pull/1104 we are slowly going to be starting to support PyTorch Tensors for some of the transforms natively in torchvision, so that this won't be an issue anymore

According to the v0.8.0 release notes, multi-channel images are now natively supported! Thanks so much for everyone's hard work!!!

Thanks @adamjstewart !

Let us know if you find any issues with it

I actually just started a new research project using drone-based hyperspectral imagery (128+ spectral bands), so I'll definitely be testing this feature to the extreme!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

martinarjovsky picture martinarjovsky  路  4Comments

iacolippo picture iacolippo  路  4Comments

ArashJavan picture ArashJavan  路  3Comments

zhang-zhenyu picture zhang-zhenyu  路  3Comments

datumbox picture datumbox  路  3Comments