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
Here I would like to discuss how to extend ToPILImage, ToTensor and transformations taking pil image as input to work with mutli-band non-uint8 images. Today, to following code does not work:
if you need to handle band combinations that are not listed above, use a sequence of Image objects.
we can modify F.to_pil_image such that it could recognize the mode for a single band and then produce a list of pil images:
ifmodeisNone:
expected_mode=_get_expected_mode(npimg.dtype)
ifexpected_modeisNone:
raiseTypeError('Input type {} is not supported'.format(npimg.dtype))
return [Image.fromarray(npimg[:, :, c], mode=expected_mode) forcinrange(npimg.shape[2])]
Next we need to change every transformation that uses PIL image as input:
either each transformation handle whether img is PIL image or list
or with a factorized code: all transformations (that uses PIL image as input) inherit from
Here I would like to discuss how to extend
ToPILImage
,ToTensor
and transformations taking pil image as input to work with mutli-band non-uint8 images. Today, to following code does not work:The error is
TypeError: Input type float32 is not supported
fromToPILImage
, because PIL does not have a mode multi-band image with depthfloat32
.As PIL documentation suggests (ref):
we can modify
F.to_pil_image
such that it could recognize the mode for a single band and then produce a list of pil images:Next we need to change every transformation that uses PIL image as input:
img
is PIL image or listand then, for example,
Resize
isFinally,
ToTensor
class will gather list of pil images into a single tensor.What do you think about this approach ? Thanks!
The text was updated successfully, but these errors were encountered: