InvalidArgumentError: Input to reshape is a tensor with 8 values, but the requested shape has 10 [Op:Reshape]
错误复现代码
lable = tf.Variable([1,2,3,4,5,6,7,8])
reshape2 = tf.reshape(lable,shape = [2,5])
with tf.Session() as sess:
print(sess.run(reshape2))
---------------------------------------------------------------------------
InvalidArgumentError Traceback (most recent call last)
Input In [XX], in <cell line: 2>()
1 lable = tf.Variable([1,2,3,4,5,6,7,8])
----> 2 reshape2 = tf.reshape(lable,shape = [2,5])
3 with tf.Session() as sess:
4 print(sess.run(reshape2))
File ~/anaconda3/envs/XXX/lib/python3.8/site-packages/tensorflow/python/util/traceback_utils.py:153, in filter_traceback.<locals>.error_handler(*args, **kwargs)
151 except Exception as e:
152 filtered_tb = _process_traceback_frames(e.__traceback__)
--> 153 raise e.with_traceback(filtered_tb) from None
154 finally:
155 del filtered_tb
File ~/anaconda3/envs/XXX/lib/python3.8/site-packages/tensorflow/python/eager/execute.py:54, in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name)
52 try:
53 ctx.ensure_initialized()
---> 54 tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
55 inputs, attrs, num_outputs)
56 except core._NotOkStatusException as e:
57 if name is not None:
InvalidArgumentError: Input to reshape is a tensor with 8 values, but the requested shape has 10 [Op:Reshape]
InvalidArgumentError: Input to reshape is a tensor with 230400 values, but the requested shape requires a multiple of 231360 [Op:Reshape]
# image_data = tf.gfile.FastGFile("./test4.jpg", 'rb').read()
import tensorflow as tf
# img_r = tf.random.normal([255,255,3], mean = 0.5, stddev = 1, dtype=tf.float32)
# img_r = tf.ones([255,255,3], dtype=tf.float32)
# image_data = tf.gfile.FastGFile("./test.jpg", 'rb').read()
image = tf.io.read_file('./test.jpg')
image = tf.image.decode_jpeg(image,channels=3)
print(image.shape,type(image)) # (240, 320, 3)
image = tf.reshape(image, [-1, 241, 320, 3])
(240, 320, 3) <class 'tensorflow.python.framework.ops.EagerTensor'>
---------------------------------------------------------------------------
InvalidArgumentError Traceback (most recent call last)
Input In [XXX], in <cell line: 14>()
10 image = tf.image.decode_jpeg(image,channels=3)
11 print(image.shape,type(image)) # (240, 320, 3)
---> 14 image = tf.reshape(image, [-1, 241, 320, 3])
File ~/anaconda3/envs/XXX/lib/python3.8/site-packages/tensorflow/python/util/traceback_utils.py:153, in filter_traceback.<locals>.error_handler(*args, **kwargs)
151 except Exception as e:
152 filtered_tb = _process_traceback_frames(e.__traceback__)
--> 153 raise e.with_traceback(filtered_tb) from None
154 finally:
155 del filtered_tb
File ~/anaconda3/envs/XXX/lib/python3.8/site-packages/tensorflow/python/eager/execute.py:54, in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name)
52 try:
53 ctx.ensure_initialized()
---> 54 tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
55 inputs, attrs, num_outputs)
56 except core._NotOkStatusException as e:
57 if name is not None:
InvalidArgumentError: Input to reshape is a tensor with 230400 values, but the requested shape requires a multiple of 231360 [Op:Reshape]
@online{BibEntry2022May,
title = {{TensorFlow报错Input to reshape is a tensor with XXX values, but the requested shape …_郑德帅的博客-CSDN博客}},
year = {2022},
month = may,
date = {2022-05-13},
urldate = {2022-05-13},
language = {chinese},
hyphenation = {chinese},
note = {[Online; accessed 13. May 2022]},
url = {https://blog.csdn.net/qq_36853469/article/details/106116375},
keywords = {TensorFlow报错Input to reshape is a tensor with XXX values, but the requested shape …},
abstract = {{完整报错代码:tensorflow.python.framework.errors_impl.InvalidArgumentError: Input to reshape is a tensor with 1600 values, but the requested shape requires a multiple of 4800分析+定位+解决:}}
}