请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

resize的时候报错:InvalidArgumentError

name = './gugong.jpg'
img_string = tf.read_file(name)
img_decoded = tf.image.decode_image(img_string)
img_decoded = tf.reshape(img_decoded, [1, 365, 600, 3])

resize_img = tf.image.resize_bicubic(img_decoded, [730, 1200])
print('resize_img shape: ', resize_img.shape)
sess = tf.Session()
img_decoded_val = sess.run(resize_img)
img_decoded_val = img_decoded_val.reshape((730, 1200, 3))
img_decoded_val = np.asarray(img_decoded_val, np.uint8)
print(img_decoded_val.shape)

%matplotlib inline
imshow(img_decoded_val)

报错如下:

InvalidArgumentError                      Traceback (most recent call last)
<ipython-input-11-dc13c12d0cb2> in <module>()
     12 print('resize_img shape: ', resize_img.shape)
     13 sess = tf.Session()
---> 14 img_decoded_val = sess.run(resize_img)
     15 img_decoded_val = img_decoded_val.reshape((730, 1200, 3))
     16 img_decoded_val = np.asarray(img_decoded_val, np.uint8)
     ...
InvalidArgumentError: Input to reshape is a tensor with 2128680 values, but the requested shape has 657000
	 [[node Reshape_7 (defined at <ipython-input-11-dc13c12d0cb2>:9) ]]

跟你的代码一样,为啥会报这个错

正在回答 回答被采纳积分+3

1回答

正十七 2021-03-22 00:08:08

错误发生在reshape这一行,可能是因为输入的图片大小不一样了,不是600 x 365的,你再check一下输入的图片大小?

0 回复 有任何疑惑可以回复我~

相似问题

登录后可查看更多问答,登录/注册

问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信