Data augmentation for 32 bit tiff images

prakash_chhipa: <p>I am applying transform on 32 bit tiff  image from the link:</p>
<aside class="onebox allowlistedgeneric" data-onebox-src="https://albumentations.ai/docs/examples/example_16_bit_tiff/">
  <header class="source">
      <img src="https://albumentations.ai/docs/examples/example_16_bit_tiff/../../images/logo.png" class="site-icon" width="190" height="182">

      <a href="https://albumentations.ai/docs/examples/example_16_bit_tiff/" target="_blank" rel="noopener nofollow ugc">albumentations.ai</a>
  </header>

  <article class="onebox-body">
    <div class="aspect-image" style="--aspect-ratio:690/309;"><img src="https://albumentations.ai/docs/images/albumentations_card.png" class="thumbnail" width="690" height="309"></div>

<h3><a href="https://albumentations.ai/docs/examples/example_16_bit_tiff/" target="_blank" rel="noopener nofollow ugc">Albumentations Documentation - Working with non-8-bit images</a></h3>

  <p>Albumentations: fast and flexible image augmentations</p>


  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>

<p>transform = A.Compose([<br>
A.ToFloat(max_value=4294967295.0),</p>
<pre><code>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),
</code></pre>
<p>])</p>
<p>my code snippet:</p>
<pre><code>    image = np.array(image, dtype='float32')

    image = self.transform[0](image= image)
</code></pre>
<p>Error:</p>
<p>image = self.transform[0](image= image)<br>
File “/home/prachh/anaconda3/lib/python3.8/site-packages/albumentations/core/composition.py”, line 191, in <strong>call</strong><br>
data = t(force_apply=force_apply, **data)<br>
File “/home/prachh/anaconda3/lib/python3.8/site-packages/albumentations/core/transforms_interface.py”, line 90, in <strong>call</strong><br>
return self.apply_with_params(params, **kwargs)<br>
File “/home/prachh/anaconda3/lib/python3.8/site-packages/albumentations/core/transforms_interface.py”, line 103, in apply_with_params<br>
res[key] = target_function(arg, **dict(params, **target_dependencies))<br>
File “/home/prachh/anaconda3/lib/python3.8/site-packages/albumentations/pytorch/transforms.py”, line 89, in apply<br>
return torch.from_numpy(img.transpose(2, 0, 1))<br>
<strong>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.</strong></p>
<p>Please suggest the possible way to augment 32 bit images in pytroch.  <a class="mention" href="/u/ptrblck">@ptrblck</a> looking forward.</p>

ptrblck: <p>I’m not deeply familiar with <code>albumentations</code> and don’t know which internal data types are used, but based on the error message it seems you cannot transform a <code>uint16</code> numpy array to a tensor so you might need to transform it to e.g. <code>int32</code> first:</p>
<pre><code class="lang-python">a = np.random.randint(0, 10, (3, 24, 24)).astype(np.uint16)
x = torch.from_numpy(a)
&gt; 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))
</code></pre>