Closed IkhlasAhmad1998 closed 3 years ago
This is due to the fact that some of your augmentations do not support 16bit floats. You can find out the dtypes supported by albumentations
in here. For example, Blur
does not support float16
(see documentation -> Image types):
This works
dummy_img = np.random.uniform(0,1, (256,256,3)).astype('float16')
AUGMENTATIONS = albumentations.Compose([
albumentations.HorizontalFlip(p=1.),
])
AUGMENTATIONS(image=dummy_img)
but this fails
dummy_img = np.random.uniform(0,1, (256,256,3)).astype('float16')
AUGMENTATIONS = albumentations.Compose([
albumentations.Blur(p=1.)
])
AUGMENTATIONS(image=dummy_img)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/tmp/ipykernel_14782/578408663.py in <module>
9 albumentations.Blur(p=1.)
10 ])
---> 11 AUGMENTATIONS(image=dummy_img)
~/anaconda3/envs/ida/lib/python3.7/site-packages/albumentations/core/composition.py in __call__(self, force_apply, *args, **data)
180 p.preprocess(data)
181
--> 182 data = t(force_apply=force_apply, **data)
183
184 if dual_start_end is not None and idx == dual_start_end[1]:
~/anaconda3/envs/ida/lib/python3.7/site-packages/albumentations/core/transforms_interface.py in __call__(self, force_apply, *args, **kwargs)
87 )
88 kwargs[self.save_key][id(self)] = deepcopy(params)
---> 89 return self.apply_with_params(params, **kwargs)
90
91 return kwargs
~/anaconda3/envs/ida/lib/python3.7/site-packages/albumentations/core/transforms_interface.py in apply_with_params(self, params, force_apply, **kwargs)
100 target_function = self._get_target_function(key)
101 target_dependencies = {k: kwargs[k] for k in self.target_dependence.get(key, [])}
--> 102 res[key] = target_function(arg, **dict(params, **target_dependencies))
103 else:
104 res[key] = None
~/anaconda3/envs/ida/lib/python3.7/site-packages/albumentations/augmentations/transforms.py in apply(self, image, ksize, **params)
2511
2512 def apply(self, image, ksize=3, **params):
-> 2513 return F.blur(image, ksize)
2514
2515 def get_params(self):
~/anaconda3/envs/ida/lib/python3.7/site-packages/albumentations/augmentations/functional.py in wrapped_function(img, *args, **kwargs)
52 def wrapped_function(img, *args, **kwargs):
53 shape = img.shape
---> 54 result = func(img, *args, **kwargs)
55 result = result.reshape(shape)
56 return result
~/anaconda3/envs/ida/lib/python3.7/site-packages/albumentations/augmentations/functional.py in blur(img, ksize)
725 def blur(img, ksize):
726 blur_fn = _maybe_process_in_chunks(cv2.blur, ksize=(ksize, ksize))
--> 727 return blur_fn(img)
728
729
~/anaconda3/envs/ida/lib/python3.7/site-packages/albumentations/augmentations/functional.py in __process_fn(img)
186 img = np.dstack(chunks)
187 else:
--> 188 img = process_fn(img, **kwargs)
189 return img
190
TypeError: Expected Ptr<cv::UMat> for argument 'src'
Nevertheless, you can fix the problem by using albumentations.Lambda
-transforms:
def to_float32(x, **kwargs):
return x.astype('float32')
def to_float16(x, **kwargs):
return x.astype('float16')
dummy_img = np.random.uniform(0,1, (256,256,3)).astype('float16')
AUGMENTATIONS = albumentations.Compose([
albumentations.Lambda(image=to_float32, p=1.),
albumentations.Blur(p=1.),
albumentations.Lambda(image=to_float16, p=1.),
])
AUGMENTATIONS(image=dummy_img)
I will close the issue.
hi, i am loading my images as float16 due to memory limitations and creating the generators like this:
but when try to get output like this:
batch ,image, mask = train_generator.next()
it throws an error:
how can i fix it? thanks