PIL图像_crop到张量,在张量流中

时间:2017-07-30 14:11:35

标签: image tensorflow

我是一名学习深度学习的学生。 我正在使用tensroflow框架并制作代码。 所以我有一个问题。 我使用Pil.image.crop制作裁剪图像 但是当我训练Pil.image.crop时无法分配张量。 那么如何将裁剪后的图像分配给张量。 Plz给我一个建议。 谢谢。 这是我的github地址 https://github.com/dldudwo0805/DeepLearningPractice

1 个答案:

答案 0 :(得分:0)

您可以使用tf.image.crop_and_resize执行此操作。这是一个例子:

from scipy.misc import imread
img = imread('flower.jpg') 

# image placeholder
X = tf.placeholder(dtype=tf.uint8, shape=(1, 300,300,3))

# You need to set the area to crop in boxes and resize it to in crop_size
Y = tf.image.crop_and_resize(X,boxes=[[.25,.25,.75,.75]], crop_size=[100, 100], box_ind=[0] )

sess = tf.InteractiveSession()
tf.global_variables_initializer().run()
out = sess.run(Y, {X:np.expand_dims(img,0)})