title: Python Tifffile: Problems with loading images in SageMaker
body: <p>I am using Tifffile to load .tiff-image files and then to convert them to a PIL image to process them. I use this workaround because other methods had problems with some specific TIFF-images. On my local machine, the following code is running fine. But when I run the code in the SageMaker environment, it does not work</p>
  <pre><code>from keras.preprocessing.image import ImageDataGenerator
  import numpy as np
  import scipy.ndimage
  import os
  import random
  import tifffile
  from PIL import Image
  from PIL.ExifTags import TAGS
  import matplotlib
  #import imagecodecs
  # Causes errors with some pictures
  #image = np.expand_dims(scipy.ndimage.imread(image_path), 0)
      
  # Causes errors with some pictures
  #image = np.expand_dims(matplotlib.pyplot.imread(image_path), 0)
      
  # This works on my local machine, but not in Amazon SageMaker
  # Use tifffile to load the image
  img = tifffile.imread(image_path)
  # Make into &quot;PIL Image&quot; and carry on as usual
  image = Image.fromarray(img)
  </code></pre>
  <p>I get the following error:</p>
  <pre><code>---------------------------------------------------------------------------
  ValueError                                Traceback (most recent call last)
  &lt;ipython-input-137-fe721f47a3dc&gt; in &lt;module&gt;
  ----&gt; 1 batch_image_augmentation(test_images, 20)
  
  &lt;ipython-input-134-b0ca28d40a9c&gt; in batch_image_augmentation(path_list, n)
        3         target_dir = &quot;./Test/&quot; + path[:-5] + &quot;_AUG&quot;
        4         print(path)
  ----&gt; 5         augment_image(path, target_dir, n)
  
  &lt;ipython-input-131-cdef2a00cd5f&gt; in augment_image(image_path, target_dir, n)
       24     #Some images cause problems, so I try the same workaround as in the PNG-conversion script
       25     # Use tifffile to load the image
  ---&gt; 26     img = tifffile.imread(image_path)
       27     # Make into &quot;PIL Image&quot; and carry on as usual
       28     image = Image.fromarray(img)
  
  /usr/local/lib/python3.6/dist-packages/tifffile/tifffile.py in imread(files, **kwargs)
      719         if isinstance(files, (str, os.PathLike)) or hasattr(files, 'seek'):
      720             with TiffFile(files, **kwargs_file) as tif:
  --&gt; 721                 return tif.asarray(**kwargs)
      722 
      723     with TiffSequence(files, **kwargs_seq) as imseq:
  
  /usr/local/lib/python3.6/dist-packages/tifffile/tifffile.py in asarray(self, key, series, level, out, maxworkers)
     2805                     typecode, product(series.shape), out=out)
     2806         elif len(pages) == 1:
  -&gt; 2807             result = pages[0].asarray(out=out, maxworkers=maxworkers)
     2808         else:
     2809             result = stack_pages(pages, out=out, maxworkers=maxworkers)
  
  /usr/local/lib/python3.6/dist-packages/tifffile/tifffile.py in asarray(self, out, squeeze, lock, reopen, maxworkers)
     5646 
     5647             for _ in self.segments(
  -&gt; 5648                 func=func, lock=lock, maxworkers=maxworkers, sort=True
     5649             ):
     5650                 pass
  
  /usr/local/lib/python3.6/dist-packages/tifffile/tifffile.py in segments(self, lock, maxworkers, func, sort)
     5510                 *self._offsetscounts, lock=lock, sort=sort, flat=True
     5511             ):
  -&gt; 5512                 yield decode(segment)
     5513         else:
     5514             # reduce memory overhead by processing chunks of up to
  
  /usr/local/lib/python3.6/dist-packages/tifffile/tifffile.py in decode(args, decodeargs, keyframe, func)
     5499 
     5500         def decode(args, decodeargs=decodeargs, keyframe=keyframe, func=func):
  -&gt; 5501             result = keyframe.decode(*args, **decodeargs)
     5502             if func is not None:
     5503                 return func(result)
  
  /usr/local/lib/python3.6/dist-packages/tifffile/tifffile.py in decode(exc, *args, **kwargs)
     5228         except KeyError as exc:
     5229             def decode(*args, exc=str(exc)[1:-1], **kwargs):
  -&gt; 5230                 raise ValueError(f'TiffPage {self.index}: {exc}')
     5231             return cache(decode)
     5232 
  ValueError: TiffPage 0: &lt;COMPRESSION.LZW: 5&gt; requires the 'imagecodecs' package
  </code></pre>
  <p>When I I try to install <em>imagecodecs</em>, pip tells me that it is already installed:</p>
  <pre><code>bash-4.2$ pip install imagecodecs
  Requirement already satisfied: imagecodecs in /opt/conda/lib/python3.7/site-packages (2020.5.30)
  Requirement already satisfied: numpy&gt;=1.15.1 in /opt/conda/lib/python3.7/site-packages (from imagecodecs) (1.19.4)
  bash-4.2$
  </code></pre>
  <p>But anyway, if I add <em>import imagecodecs</em> to the imports, I get the following error:</p>
  <pre><code>---------------------------------------------------------------------------
  ModuleNotFoundError                       Traceback (most recent call last)
  &lt;ipython-input-138-920d3e93091b&gt; in &lt;module&gt;
        8 from PIL.ExifTags import TAGS
        9 import matplotlib
  ---&gt; 10 import imagecodecs
       11 
       12 # https://gis.stackexchange.com/questions/365950/how-can-i-solve-this-error-from-tiff-file
  
  ModuleNotFoundError: No module named 'imagecodecs'
  </code></pre>
  <p>Does anyone know a solution for this problem?</p>