Reputation: 1296
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?
Upvotes: 1
Views: 4004
Reputation: 39
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)
Upvotes: -1
Reputation: 760
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.
Upvotes: 3
Reputation: 433
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)
Upvotes: 2