1

I want to retrain inception module on tiff images. I have followed the steps in https://codelabs.developers.google.com/codelabs/tensorflow-for-poets/#0. However, it seems tiff images are not supported by inception module because I have received the following error

2017-06-22 16:52:56.712653: W tensorflow/core/platform    /cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1     instructions, but these are available on your machine and could speed up CPU     computations.
Looking for images in 'Type 1'
No files found
Looking for images in 'Type 2'
No files found
No valid folders of images found at Myfolder

Is there any way to handle this issue?

desertnaut
  • 57,590
  • 26
  • 140
  • 166
Mehdi
  • 1,146
  • 1
  • 14
  • 27
  • As of February 2019, some (limited & experimental) TIFF support has been added as part of the Tensorflow I/O library; see https://stackoverflow.com/a/67186083/4685471 – desertnaut Apr 20 '21 at 20:53

3 Answers3

3

You're right in saying that TensorFlow does not support TIFF images.

See here: No Tensorflow decoder for TIFF images?

If you want to use TIFF images, you could use a library like PIL or Pillow which can read TIFF images and convert them into a numpy array to feed into TensorFlow.

See Working with TIFFs (import, export) in Python using numpy for an example.

If you have a large amount of TIFF files, the above would make training slow as you will be spending more time reading and decoding TIFF files starving the GPU of data.

In this case, take a look at https://www.tensorflow.org/extend/new_data_formats on how to support custom file formats.

desertnaut
  • 57,590
  • 26
  • 140
  • 166
gokul_uf
  • 740
  • 1
  • 8
  • 21
2

If you would like to go with the conversion route, this code, which I adapted with slight modification from Lipin Yang's website, worked nicely to convert TIFF to JPEG for a recent TensorFlow project.

import os
from PIL import Image

current_path = os.getcwd()
for root, dirs, files in os.walk(current_path, topdown=False):
    for name in files:
        print(os.path.join(root, name))
        #if os.path.splitext(os.path.join(root, name))[1].lower() == ".tiff":
        if os.path.splitext(os.path.join(root, name))[1].lower() == ".tif":
            if os.path.isfile(os.path.splitext(os.path.join(root, name))[0] + ".jpg"):
                print ("A jpeg file already exists for %s" % name)
            # If a jpeg with the name does *NOT* exist, convert one from the tif.
            else:
                outputfile = os.path.splitext(os.path.join(root, name))[0] + ".jpg"
                try:
                    im = Image.open(os.path.join(root, name))
                    print ("Converting jpeg for %s" % name)
                    im.thumbnail(im.size)
                    im.save(outputfile, "JPEG", quality=100)
                except Exception as e: 
                  print(e)
Beau Hilton
  • 413
  • 5
  • 7
-1

To save .jpg files in another directory (Extending Beau Hilton's answer)

main_path = "your/main/path"
data_folder = os.path.join(main_path, "Images_tiff")
data_folder_jpg = os.path.join(main_path, "Images_jpg")

if not os.path.isdir(data_folder_jpg):
  os.mkdir(data_folder_jpg)

for root, dirs, files in os.walk(data_folder, topdown=False):
    new_folder = os.path.join(data_folder_jpg,os.path.split(root)[1])
    if (not os.path.exists(new_folder)) and files:
      os.mkdir(new_folder)
    for name in files:
        print(os.path.join(root, name))
        #if os.path.splitext(os.path.join(root, name))[1].lower() == ".tiff":
        if os.path.splitext(os.path.join(root, name))[1].lower() == ".tif":
            if os.path.isfile(os.path.splitext(os.path.join(new_folder, name))[0] + ".jpg"):
                print ("A jpeg file already exists for %s" % name)
            # If a jpeg with the name does *NOT* exist, convert one from the tif.
            else:
                outputfile = os.path.splitext(os.path.join(new_folder, name))[0] + ".jpg"
                try:
                    im = Image.open(os.path.join(root, name))
                    print ("Converting jpeg for %s" % name)
                    im.thumbnail(im.size)
                    im.save(outputfile, "JPEG", quality=100)
                except Exception as e: 
                    print(e)
MBMS80
  • 39
  • 4