I am trying to read and decode tiff images in tensorflow. I am using tensrflow_io package as follows, I am getting this error that I cant figure out.
import tensorflow as tf
import tensorflow_io as tfio
import os
def process_image(image):
image = tf.io.read_file(image)
image = tfio.experimental.image.decode_tiff(image)
image = tfio.experimental.color.rgba_to_rgb(image)
return image
path = os.path.join(os.curdir, '*.TIF')
files = tf.data.Dataset.list_files(path)
Output:
for file in files.take(5):
print(file)
tf.Tensor(b'./SIMCEPImages_A01_C1_F1_s10_w1.TIF', shape=(), dtype=string)
tf.Tensor(b'./SIMCEPImages_A01_C1_F1_s04_w1.TIF', shape=(), dtype=string)
tf.Tensor(b'./SIMCEPImages_A01_C1_F1_s12_w1.TIF', shape=(), dtype=string)
tf.Tensor(b'./SIMCEPImages_A01_C1_F1_s04_w2.TIF', shape=(), dtype=string)
tf.Tensor(b'./SIMCEPImages_A01_C1_F1_s11_w1.TIF', shape=(), dtype=string)
Now if I call:
dataset = files.map(process_image, num_parallel_calls=tf.data.experimental.AUTOTUNE)
for img in dataset.take(5):
print(img.shape)
ValueError: in user code:
File "<ipython-input-4-1d2deab36c6d>", line 5, in process_image *
image = tfio.experimental.color.rgba_to_rgb(image)
File "/usr/local/lib/python3.7/dist-packages/tensorflow_io/python/experimental/color_ops.py", line 80, in rgba_to_rgb *
rgba = tf.unstack(input, axis=-1)
ValueError: Cannot infer argument `num` from shape (None, None, None)
CodePudding user response:
The problem is that tfio.experimental.color.rgba_to_rgb
uses unstack
under the hood, which cannot work in