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
{{ message }}
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
Originally posted by Nico995 July 17, 2022
Hello, I have been trying run a SemanticSegmentation task on a custom dataset with no luck. The problem I'm facing is that it looks like paletted png images are not supported as targets for the task.
TL;DR
ImageSegmentationData.from_files breaks when target files are paletted PNG images.
Next, I took a second to examine the format of the segmentation mask. As it turns out, the images are in RGB format, where the R channel contains the class index for each pixel, and the GB channels are set to 0. You can verify that with the following code:
I believe I have seen this error many times already, and I think it is referring to a loss function call when the argument contains values larget than the number of classes declared. My first guess is that this is happening because flash default behavior is to convert the mask to RGB, and reading only the first channel. Below I try to justify my assumption.
I believe this is the line responsible for extracting the first channel:
defimage_default_loader(file_path: str, drop_alpha: bool=True) ->Image:
"""Default loader for images. Args: file_path: The image file to load. drop_alpha: If ``True`` (default) then any alpha channels will be silently removed. """img=default_loader(file_path) <---ifimg.mode=="RGBA"anddrop_alpha:
img=img.convert("RGB")
return
Which in turn is a pytorch function that simply loads a RGB image
Hi @Nico995, I have able to generate the error (however, I had to use two files, since, for one file, the shape comes out to be (256, 256)), and I got the error as IndexError: Target 64 is out of bounds.. I guess you are right as well, i.e allowing a bit of modifiable reading format would help in customizing the package on different sets of data and tasks. Are you still working on it, or have found any approach to solve the problem?
Hi @uakarsh, sorry for the late reply.
I have not been checking this in a long time. It appears that either I got the code reference from the wrong branch, or the master branch changed. Anyways, now the official code looks like this:
which breaks my example at point n.3 with the following error:
Expected input batch_size (1) to match target batch_size (128).
I did not take the time to fully debug the code, but I suppose one could at least include support for P-formatted images since they fit the description of a segmentation target incredibly well.
Anyways, the quick&dirty solution I am using at the moment is removing the .transpose((2, 0, 1)) when working with paletted images.
Discussed in #1397
Originally posted by Nico995 July 17, 2022
Hello, I have been trying run a SemanticSegmentation task on a custom dataset with no luck. The problem I'm facing is that it looks like paletted png images are not supported as targets for the task.
TL;DR
ImageSegmentationData.from_files breaks when target files are paletted PNG images.
Reproducing a working example
To prove my point, I started from the segmentation example on flash website:
The mask looks completely black because PIL in RGB mode (x, 0, 0) colors with 0<x<12 are black/red-ish colors.
Testing Paletted images
The problem arises when I try to use the paletted version of the same mask, as follows:
The whole traceback is very long, but the key line is the following
Suspected problem
I believe I have seen this error many times already, and I think it is referring to a loss function call when the argument contains values larget than the number of classes declared. My first guess is that this is happening because flash default behavior is to convert the mask to RGB, and reading only the first channel. Below I try to justify my assumption.
I believe this is the line responsible for extracting the first channel:
And this is the line responsible for the RGB conversion
Which in turn is a pytorch function that simply loads a RGB image
Possible solution
I think it would be nice to have a parameter in SemanticSegmentationFilesInput.from_folders inside /flash/image/segmentation/data.py that allows the user to specify the mode of the image.
The parameter would default to 'RGB' for backward compatibility, and could be set to 'P' if one wants to work with paletted images.
Let me know if this looks like a possible enhancement, or if I just simply missed a parameter somewhere that would solve the problem :)
The text was updated successfully, but these errors were encountered: