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

request for adding 4 bands-image training #8405

Closed
wants to merge 4 commits into from
Closed

Conversation

Floyd2yh
Copy link

@Floyd2yh Floyd2yh commented May 3, 2024

Aerial and satellite images taken with a drone are,typically in 4-band geotiff format.
A 4-band image is an RBGN image, which is a 3-band RGB plus near-infrared
(NIR) to the 3-band RGB.
This modification is needed to train the 4band-image without processing.

Copy link

pytorch-bot bot commented May 3, 2024

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/vision/8405

Note: Links to docs will display an error until the docs builds have been completed.

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot
Copy link

Hi @Floyd2yh!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@abhi-glitchhg
Copy link
Contributor

If image has 4 channels, doesn't mean we should load all 4 channels. It would be better if pil_loader takes optional parameter which indicates whether to return RGB only or PIL image without any conversion

Because sometimes images have alpha channel (RGBA image) which are mostly constant value. In those cases, it's required to get rid of alpha channel.

@Floyd2yh
Copy link
Author

Floyd2yh commented May 4, 2024

abhi-glitchhg, thank you for your advice.
I agree with your point about PNG (RBGA).
However, adding an optional argument would also cause changes to the caller, which would be a major modification. Also, the conversion to RGBX is necessary even for a 4-band image. I have uploaded a corrected version. What do you think?

@Floyd2yh
Copy link
Author

Floyd2yh commented May 4, 2024

uploaded modified code

@abhi-glitchhg
Copy link
Contributor

abhi-glitchhg commented May 7, 2024

I think we need to take a review/comments from maintainers in this approach. Maybe @pmeier or @NicolasHug ?? What do you guys think??

@@ -258,10 +258,13 @@ def __len__(self) -> int:


def pil_loader(path: str) -> Image.Image:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was suggesting something like this. This would be backward compatible as the default conversion is RGB. And in special cases where we want the conversation to other color space, (like RGBX) in your case we could handle that as well. Basically a more generalised solution.

Suggested change
def pil_loader(path: str) -> Image.Image:
def pil_loader(path: str, convert_to="RGB") -> Image.Image:

@Floyd2yh
Copy link
Author

Floyd2yh commented May 7, 2024

abhi-glitchhg, ok I understood.
but how can I set loader?

train_data = datasets.ImageFolder(root=train_dataset_dir, transform=train_transforms, loader=????????)
will you teach me?

@NicolasHug
Copy link
Member

Thanks for the PR @Floyd2yh .

The ImageFolder class exposes a loader attribute that you can override to a custom loader. I'd suggest simply doing that locally.
Unfortunately we won't be able to include the change within torchvision, because our transforms expect RGB images with 3 channels instead of 4.

@NicolasHug NicolasHug closed this May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants