io
io copied to clipboard
`decode_tiff()` DecodeTiff InvalidArgumentError: unable to read directory
I am having an issue reading a TIFF with tensorflow.io, despite following the TF IO example in the documentation.
All of this is ultimately trying to mimic the image_dataset_from_directory function but using 32-bit TIFF images (more specifically, digital elevation models (DEM)) that have been sampled from a larger TIFF. The problem I'm having is getting the decode_tiff function from tensorflow.io working. The input TIFF is 850 MB (109,396 x 85,075 pixels with 32-bit floating point values) and I am working with a Lenovo mobile workstation with Windows 10, an Intel i9-11950H processor, 64 GB RAM, and an NVIDIA GeForce RTX 3080 Laptop GPU.
Here is the script I am running (script prints version info to the console):
import os, platform
import tensorflow as tf
import tensorflow_io as tfio
print("Versions:")
print(" Tensorflow: {}".format(tf.__version__))
print(" Tensorflow.io: {}".format(tfio.__version__))
print(" Python: {}".format(platform.python_version()))
img_path = "E:\\Depth_N.tif"
print("Input Image: {}".format(img_path))
if os.path.exists(img_path):
image = tf.io.read_file(img_path)
tfimg = tfio.experimental.image.decode_tiff(image, index=0)
The console output is:
memory: Sorry, can not handle images with 32-bit samples.
Versions:
Tensorflow: 2.9.1
Tensorflow.io: 0.26.0
Python: 3.10.4
Input Image: E:\Depth_N.tif
Traceback (most recent call last):
File "E:\load_tif_dataset_from_dir.py", line 27, in <module>
tfimg = tfio.experimental.image.decode_tiff(image, index=0)
File "C:\ProgramData\Anaconda3\envs\ml39\lib\site-packages\tensorflow_io\python\experimental\image_ops.py", line 87, in decode_tiff
return core_ops.io_decode_tiff(contents, index, name=name)
File "<string>", line 6306, in io_decode_tiff
File "C:\ProgramData\Anaconda3\envs\ml39\lib\site-packages\tensorflow\python\framework\ops.py", line 7164, in raise_from_not_ok_status
raise core._status_to_exception(e) from None # pylint: disable=protected-access
tensorflow.python.framework.errors_impl.InvalidArgumentError: unable to read directory: 0 [Op:IO>DecodeTiff]
The drive is completely open to all users for read and write and there is no encryption on it. Even the file In here is another (maybe related?) issue of the "Sorry, can not hangle images with 32-bit samples." message I receive. Any assistance would be much appreciated.
I would expect the TIFF image to read into memory with the decode_tiff() function and have more than enough memory to create a 32-bit floating array of the same size as the input raster dimensions (have already done this with a larger raster).
have you found a solution yet ?
No solution yet. This issue is holding up one of our large-scale modelling efforts though so I'm still searching for a solution.
I'm looking at having to modify a (copied) local version of the TF.io base code to see if I can get it to work.
Right now my thought is to use the rasterio package to read the TIFF files and then convert the resulting numpy array to a Tensor object using the TF built-in functions. But, if anybody has thoughts on this or other suggestions I'm open.
Did you get it to work?
I wasn't able to get this working. My best workaround was to convert the TIFF files to VRT and read them as VRT files. Although it's not 100% what I was looking for, I guess it'll work for now.