load tiff images in tensorflow using tensorflow-io's decode_tiff

1

I have a dataset of tiff images and I am trying to load the images from a dataframe having a column of image paths using tfio.experimental.image.decode_tiff as tensorflow currently does not have support for it.

tensorflow version: 2.3.0

tensorflow-io version: 0.15.0.dev20201015045556

list_ds = tf.data.Dataset.from_tensor_slices(df['image_path'].values)

image_count = 86
val_size = int(image_count * 0.2)
train_ds = list_ds.skip(val_size)
val_ds = list_ds.take(val_size)

def decode_img(img):

  img = tfio.experimental.image.decode_tiff(img, index=0, name=None)

  # resize the image to the desired size
  return tf.image.resize(img, [256, 256])


def process_path(file_path):

  # load the raw data from the file as a string
  img = tf.io.read_file(file_path)
  img = decode_img(img)

  return img

AUTOTUNE = tf.data.experimental.AUTOTUNE

# Set `num_parallel_calls` so multiple images are loaded/processed in parallel.
train_ds = train_ds.map(process_path, num_parallel_calls=AUTOTUNE)
val_ds = val_ds.map(process_path, num_parallel_calls=AUTOTUNE)

When I am trying to run the following code to visualize images:


image_batch = next(iter(train_ds))

plt.figure(figsize=(2, 2))
for i in range(9):
  ax = plt.subplot(3, 3, i + 1)
  plt.imshow(image_batch[i].numpy().astype("uint8"))
  #label = label_batch[i]

plt.show()

The first line itself is giving this error:

Assertion failed: sizeof(tmsize_t)==sizeof(void*), file external/libtiff/libtiff/tif_open.c, line 99

Process finished with exit code -1073740791 (0xC0000409)

And it is running endlessly in the python console.

I have looked at various issues :

https://github.com/tensorflow/io/issues/957

https://github.com/tensorflow/io/issues/831

But could not find the solution.

I want to load the images in tensorflow only to make use of tensorflow dataset API to enhance performance, as my dataset is quite large. So, let me know if someone have a better idea how to load tiff supported images in tensorflow.

python
tensorflow
image-processing
asked on Stack Overflow Oct 19, 2020 by Arun Rajora • edited Oct 19, 2020 by Arun Rajora

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0