I am working on an image classification project involving multi-image TIFF files. I have my current directory set up like this:
data
|
|__class1
| |
| |__ file1.tiff
| |__ file2.tiff
|
|__class2
|
|__ file3.tiff
...
Each TIFF represents a multi-channel microscopy image (3 channels) so I would like to use all of them for learning.
I tried the following code for PNG files, with some success:
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import preprocessing
keras.backend.clear_session()
image_size = (1280, 1024)
batch_size = 2
# Import images as a dataset
training = tf.keras.preprocessing.image_dataset_from_directory(
"./data/",
validation_split=0.1,
color_mode = 'grayscale',
subset="training",
label_mode='int',
seed=1337,
image_size=image_size,
batch_size=batch_size,
)
and I am getting the following error:
Traceback (most recent call last):
File "/home/E627046/miniconda3/envs/cellimaging/lib/python3.8/site-packages/te nsorflow/python/framework/op_def_library.py", line 517, in _apply_op_helper
values = ops.convert_to_tensor(
File "/home/E627046/miniconda3/envs/cellimaging/lib/python3.8/site-packages/te nsorflow/python/profiler/trace.py", line 163, in wrapped
return func(*args, **kwargs)
File "/home/E627046/miniconda3/envs/cellimaging/lib/python3.8/site-packages/te nsorflow/python/framework/ops.py", line 1507, in convert_to_tensor
raise ValueError(
ValueError: Tensor conversion requested dtype string for Tensor with dtype float 32: <tf.Tensor 'args_0:0' shape=() dtype=float32>
I am more overall confused as to the best solution to load these TIFF files into python to start the classification pipeline. I debated whether to convert these TIFF files to PNG files, but I was not sure if that would work because these TIFF files are multi-imaged, which I am pretty sure is not supported by PNG. I would really like to preserve the dimensionality. Please let me know if there are any suggestions on how to approach this "TIFF stack" problem.