2017-07-30 257 views

回答

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)})