【问题标题】:How to make image cube for 3d convolution with file path如何使用文件路径制作用于 3d 卷积的图像立方体
【发布时间】:2021-01-10 08:57:48
【问题描述】:

最近在研究用tensorflow进行视频图像处理的3d卷积。

我用教程博客制作模型。但我想制作我的自定义数据集。我的输入图像的形状是(128,128,3),我想制作图像立方体(128,128,100,3)。我使用 tensorflow.data.dataset 并尝试通过回忆我用于 2d 卷积的记忆来创建一个映射函数。由于使用 NumPy 时内存不足,我想使用包含 (Number of image cube, 100) 和 tf.data.dataset 映射函数的路径来对多维数据集进行映像。

我尝试使用如下代码

def load_image(path):
    images = []
    for i, p in enumerate(path):
        image_string = tf.io.read_file(p)
        image = tf.io.decode_jpeg(p, channels=3)
        image = tf.reshape(image, [128,128,1,3])
        image = image / 255
        images.append(image)
    image_block = tf.concat(images, axis=2)
    return image_block

train_data = tf.data.Dataset.from_tensor_slices(total_files) # shape (1077,100)
train_data = train_data.map(load_images, num_parallel_calls=tf.data.experimental.AUTOTUNE)

但是有张量的形状改变的错误。我也使用 .assign 使用 tf.Variable 但有类似的错误。

如何用路径制作3d卷积的输入图像立方体???我使用 tensorflow 2.0。

【问题讨论】:

  • 你能显示完整的错误信息吗?
  • peratorNotAllowedInGraphError: 在图形执行中不允许迭代 tf.Tensor。使用 Eager 执行或使用 @tf.function 装饰此函数。

标签: tensorflow conv-neural-network


【解决方案1】:

所以你不能像for x in tensor 这样迭代张量。在这种情况下,您可以例如遍历范围并通过索引获取值,例如

for x in range(tf.shape(tensor)[0]):
   y = tensor[x]

【讨论】:

  • 当您执行tf.data.Dataset.from_tensor_slices(total_files) 时,您正在创建包含张量的数据集。因此,当您执行 train_data.map() 时,您将张量作为参数传递。
  • 谢谢!!我按照你说的做了,运行没有错误!!
猜你喜欢
  • 2019-05-24
  • 2020-05-26
  • 1970-01-01
  • 2019-03-09
  • 1970-01-01
  • 2020-05-27
  • 2023-03-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多