- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用 tf.keras
构建了一个简单的模型和 tf.data.Dataset
用于高效加载,因为数据集有几 GB 大。
图片在tiff
格式,因此需要直接加载为 numpy.array
.
我确实有一个标签和文件路径的数据集,并且想要映射一个用于加载该数据集的函数。因此,我必须以某种方式从张量中获取 python 字符串表示。
我尝试使用通常的 tf.Tensor.eval()
然后将字符加入一个完整的字符串,但得到错误:ValueError: Cannot evaluate tensor using
评估(): No default session is registered.
这确实有意义,因为在执行 keras 模型之前没有 session
然后我试着把 tf.enable_eager_execution()
在数据集文件中我的 tensorflow 导入正下方(并从 .eval()
更改为 .numpy()
),但出现错误:AttributeError: 'Tensor' object has not attribute 'numpy'
暗示tf.enable_eager_execution()
不工作
基本上我正在尝试读取以下张量 a 中包含的字符串:
path = tf.decode_raw(path, tf.uint8)
path = ''.join(map(chr, path.eval())) # with session
path = ''.join(map(chr, path.numpy())) # with eager execution
image = PIL.Image.open(path)
image = numpy.array(image)
当在单个文件中“原型(prototype)设计”而没有其余部分时,两者都可以正常工作,但在具有例如我的模型在
model.py
和
dataset.py
中的数据集但有
tf.enable_eager_execution()
同时
最佳答案
这个问题很老了,但因为它可能对某人有用,这将是我的方法:
您可以使用 tf.io.read_file 读取文件,然后将其转换为带有 tf.image.decode_png 的图像如果您的图像是png。有几种其他格式可用。
与 tf_filepath 张量中包含的 RGB 图像的路径
image = tf.io.read_file(tf_filepath)
image = tf.image.decode_png(image, channels=3, dtype=tf.uint8)
关于tensorflow - 从 tf.Tensor 中包含的路径加载文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58085880/
我是一名优秀的程序员,十分优秀!