【发布时间】:2017-05-26 16:39:43
【问题描述】:
我之前曾问过这个问题,但在对该问题进行了一些调查后,我似乎只是走错了路,以实现我想要实现的目标。
Dynamic image cropping in Tensorflow
我想也许这可能是一个更好的尝试途径。但是我不知道的部分是我应该为切片操作的 size 参数添加什么。从根本上说,我想要实现的是能够动态决定如何裁剪图像,然后裁剪它,然后在我的计算图中继续使用这些裁剪的图像。如果这似乎是一种低效的解决方法,请随时提供替代方法。
import numpy as np
import tensorflow as tf
img1 = np.random.random([400, 600, 3])
img2 = np.random.random([400, 600, 3])
img3 = np.random.random([400, 600, 3])
images = [img1, img2, img3]
img1_crop = [100, 100, 100, 100]
img2_crop = [200, 150, 100, 100]
img3_crop = [150, 200, 100, 100]
crop_values = [img1_crop, img2_crop, img3_crop]
x = tf.placeholder(tf.float32, shape=[None, 400, 600, 3])
i = tf.placeholder(tf.int32, shape=[None, 4])
y = tf.slice(x, i, size="Not sure what to put here")
# initialize
init = tf.global_variables_initializer()
sess = tf.Session()
sess.run(init)
# run
result = sess.run(y, feed_dict={x: images, i: crop_values})
print(result)
【问题讨论】:
标签: image python-3.x tensorflow slice crop