作为我正在处理的CNN的输入,我想使用一系列图像(在卷积层中进行3D卷积)。
但是,我已经无法将图像读取为可以用于计算的3D张量。
这是我的原始尝试:
def get_sequence_as_tensor(folder):
images = [folder + "/depth-%i.png" for i in range(15)]
tensor = tf.zeros(shape=(480, 640, 15), dtype=tf.float32)
for i, image in enumerate(images):
img = tf.image.decode_png(image)
img_float = tf.cast(img, tf.float32)
img_float = tf.reshape(img_float, (480, 640))
tensor[:, :, i] = img_float
return tensor这已经失败了,因为我不能像我期望的那样在numpy数组中使用带有张量的索引表示法。
TypeError: 'Tensor' object does not support item assignment将一系列图像作为3d张量读取的合适方式是什么?
发布于 2016-07-26 00:38:11
我建议将图像组合到tensorflow外部的numpy数组中,然后将它们传递给占位符。
像这样的东西应该行得通。
filename = tf.placeholder("string")
png_string = tf.read_file(filename)
img = tf.image.decode_png(png_string)
img_float = tf.cast(img, tf.float32)
img_float = tf.reshape(img_float, (480, 640))
images = tf.placeholder("float", (480, 640, 15))
output = some_operation(images)
sess = tf.Session()
images_array = np.zeros((480, 640, 15), np.float32)
for i, image in enumerate(filenames):
images_array[:,:,i] = sess.run(img_float, feed_dict{filename: image})
out = sess.run(output, feed_dict={images: images_array})我希望这能帮到你。
https://stackoverflow.com/questions/38569663
复制相似问题