Python 使用“tf.image.resize\u image\u和\u crop\u或\u pad”调整numpy数组的大小

Python 使用“tf.image.resize\u image\u和\u crop\u或\u pad”调整numpy数组的大小,python,numpy,tensorflow,Python,Numpy,Tensorflow,我想在形状(100100,2)的Numpy数组上使用,以将其裁剪或填充到目标形状(h,w,2) 然而,当我这样做时: img = resize_image_with_crop_or_pad(img, target_height, target_width) img = np.array(img) img.shape的计算结果为(),这不是我所期望的。如何将此函数的输出转换为正确形状的numpy数组 img = resize_image_with_crop_or_pad(img_tensor,

我想在形状
(100100,2)
的Numpy数组上使用,以将其裁剪或填充到目标形状
(h,w,2)

然而,当我这样做时:

img = resize_image_with_crop_or_pad(img, target_height, target_width)
img = np.array(img)
img.shape
的计算结果为
()
,这不是我所期望的。如何将此函数的输出转换为正确形状的numpy数组

img = resize_image_with_crop_or_pad(img_tensor, target_height, target_width)
with tf.Session as sess:
    img_output = sess.run(img)
现在,
img\u输出
是一个numpy数组,但请注意,img必须是一个形状为
[1,高度,宽度,通道]
tf.张量
,因此您可以事先这样做,这表明您的输入图像已经是一个numpy数组:

img_input = np.expand_dims(img_input, 0)
img_tensor = tf.convert_to_tensor(img_input)

您为什么要使用img=np.array(img)呢?您需要定义会话对象并正确运行或计算变量。否则,您的第一行仍然是op,因此,您的下一行将不会计算为任何内容会话调用中有输入错误(应该是:tf.session(),带括号)