Data augmentation for 32 bit tiff images

I am applying transform on 32 bit tiff image from the link:

transform = A.Compose([
A.ToFloat(max_value=4294967295.0),

A.RandomRotate90(),
A.Flip(),
A.OneOf([
    A.MotionBlur(p=0.2),
    A.MedianBlur(blur_limit=3, p=0.1),
    A.Blur(blur_limit=3, p=0.1),
], p=0.2),
A.ShiftScaleRotate(shift_limit=0.0625, scale_limit=0.2, rotate_limit=45, p=0.2),
A.OneOf([
    A.OpticalDistortion(p=0.3),
    A.GridDistortion(p=0.1),
], p=0.2),        
A.HueSaturationValue(hue_shift_limit=20, sat_shift_limit=0.1, val_shift_limit=0.1, p=0.3),

A.FromFloat(max_value=4294967295.0),

])

my code snippet:

    image = np.array(image, dtype='float32')

    image = self.transform[0](image= image)

Error:

image = self.transform[0](image= image)
File “/home/prachh/anaconda3/lib/python3.8/site-packages/albumentations/core/composition.py”, line 191, in call
data = t(force_apply=force_apply, **data)
File “/home/prachh/anaconda3/lib/python3.8/site-packages/albumentations/core/transforms_interface.py”, line 90, in call
return self.apply_with_params(params, **kwargs)
File “/home/prachh/anaconda3/lib/python3.8/site-packages/albumentations/core/transforms_interface.py”, line 103, in apply_with_params
res[key] = target_function(arg, **dict(params, **target_dependencies))
File “/home/prachh/anaconda3/lib/python3.8/site-packages/albumentations/pytorch/transforms.py”, line 89, in apply
return torch.from_numpy(img.transpose(2, 0, 1))
TypeError: can’t convert np.ndarray of type numpy.uint16. The only supported types are: float64, float32, float16, complex64, complex128, int64, int32, int16, int8, uint8, and bool.

Please suggest the possible way to augment 32 bit images in pytroch. @ptrblck looking forward.

I’m not deeply familiar with albumentations and don’t know which internal data types are used, but based on the error message it seems you cannot transform a uint16 numpy array to a tensor so you might need to transform it to e.g. int32 first:

a = np.random.randint(0, 10, (3, 24, 24)).astype(np.uint16)
x = torch.from_numpy(a)
> TypeError: can't convert np.ndarray of type numpy.uint16. The only supported types are: float64, float32, float16, complex64, complex128, int64, int32, int16, int8, uint8, and bool.

x = torch.from_numpy(a.astype(np.int32))