tensorflow_io:value error:无法从形状推断num`(无,无,无)
我正在尝试在TensorFlow中读取和解码TIFF图像。我使用的是Tensrflow_io软件包,如下所示,我会发现我无法弄清楚的错误。
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)
输出:
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)
如果我打电话:
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是
tfio.experiment.color.rgba_to_rgb
使用unstack
在引擎盖下,它无法在指南/Intro_to_graphs“ rel =“ nofollow noreferrer”>图形模式。一种解决方案是根据源代码对于rgba_to_rgb
。这是一个工作示例:如果您真的想使用
tfio.experiment.color.rgba_to_rgb
,它将不在图形模式下,例如tf.py_function
。The problem is that
tfio.experimental.color.rgba_to_rgb
usesunstack
under the hood, which cannot work in graph mode. One solution would be to manually index the channels you want according to the source code forrgba_to_rgb
. Here is a working example:If you really want to use
tfio.experimental.color.rgba_to_rgb
, it will have be out of graph mode, using for exampletf.py_function
.我更改了一些代码,这是因为该参数未按照您的预期进行更新,这种方式很容易理解。 (arg 0)
[示例]:
[输出]:
示例
I changed a bit of code that is because the argument is not updated as you expected, this way is easy to understand. ( arg 0 )
[ Sample ]:
[ Output ]:
Sample