Python Tfrecords错误:";无效参数:重塑的输入是一个值为71680的张量,但请求的形状有8960“;
在那些日子里,当我运行代码读取“tfrecords”数据时,就会出现这个错误。问题是如何找到“值为71680的张量”或“形状为8960”的张量 错误是: 我认为关键在于Python Tfrecords错误:";无效参数:重塑的输入是一个值为71680的张量,但请求的形状有8960“;,python,tensorflow,Python,Tensorflow,在那些日子里,当我运行代码读取“tfrecords”数据时,就会出现这个错误。问题是如何找到“值为71680的张量”或“形状为8960”的张量 错误是: 我认为关键在于images=tf.decode_raw(功能['image_raw',tf.uint8),但我不知道原因和方法。这里我给出了生成“tfrecords”数据的代码 当我使用PIL.Image替换cv2时,它工作正常!这里的图像高=32,宽=280。有人知道为什么它发生在cv2中吗?或者我如何从tfrecords数据中正确读取图像。
images=tf.decode_raw(功能['image_raw',tf.uint8)
,但我不知道原因和方法。这里我给出了生成“tfrecords”数据的代码
当我使用
PIL.Image
替换cv2
时,它工作正常!这里的图像高=32,宽=280。有人知道为什么它发生在cv2中吗?或者我如何从tfrecords
数据中正确读取图像。问题已经解决。问题在这里:image=image/255.0-0.5
。有人知道为什么吗?问题已经解决。问题在这里:image=image/255.0-0.5
。有人知道为什么吗?请编辑这篇文章,包括crnn
看起来像。对不起,我不明白我的错误。在这里我重新写了我的错误地点的详细信息请编辑这篇文章,包括crnn
的样子。对不起,我没有理解我的错误。在这里,我重新写下我的错误详细的地方
I0807 09:54:11.147000 353860 coordinator.py:224] Error reported to Coordinator: <class 'tensorflow.python.framework.errors_impl.InvalidArgumentError'>, 2 root error(s) found.
(0) Invalid argument: Input to reshape is a tensor with 71680 values, but the requested shape has 8960
[[{{node Reshape}}]]
(1) Invalid argument: Input to reshape is a tensor with 71680 values, but the requested shape has 8960
[[{{node Reshape}}]]
[[sub/_21]]
0 successful operations.
0 derived errors ignored.
Traceback (most recent call last):
File "D:\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 1356, in _do_call
return fn(*args)
File "D:\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 1341, in _run_fn
options, feed_dict, fetch_list, target_list, run_metadata)
File "D:\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 1429, in _call_tf_sessionrun
run_metadata)
tensorflow.python.framework.errors_impl.OutOfRangeError: 2 root error(s) found.
(0) Out of range: RandomShuffleQueue '_2_shuffle_batch/random_shuffle_queue' is closed and has insufficient elements (requested 4, current size 0)
[[{{node shuffle_batch}}]]
(1) Out of range: RandomShuffleQueue '_2_shuffle_batch/random_shuffle_queue' is closed and has insufficient elements (requested 4, current size 0)
[[{{node shuffle_batch}}]]
[[CTCLoss/_121]]
0 successful operations.
0 derived errors ignored.
def read_tfrecords():
......
......
filename_queue = tf.train.string_input_producer([tfrecords_path])
reader = tf.TFRecordReader()
_,serizalized_example = reader.read(filename_queue)
features = tf.parse_single_example(serizalized_example,
features = {
'image_raw':tf.FixedLenFeature([], tf.string),
'label': tf.VarLenFeature(tf.int64),
})
images = tf.decode_raw(features['image_raw'],tf.uint8) # Maybe error is here
images = tf.cast(images,dtype = tf.float32)
images = tf.reshape(images, [32, 280, 1])
labels = tf.cast(features['label'], tf.int32)
images_batch, label_batch = tf.train.shuffle_batch([images,labels],batch_size=batch_size,num_threads=1,
capacity=5000, min_after_dequeue=1000)
return images_batch, label_batch
def write2tfrecords():
....
....
image = cv2.imread(image_path,0)
image = cv2.resize(image, (280, 32))
image = image/255.0-0.5
image_raw = image.tobytes() ## I think the error is here
#image_raw = image.tostring() ## It also don't work
value_label = lable
example = tf.train.Example(features = tf.train.Features(
feature={
'image_raw':tf.train.Feature(bytes_list=tf.train.BytesList(value=[image_raw])),
'label':tf.train.Feature(int64_list=tf.train.Int64List(value=[value_label]))
}))
writer.write(example.SerializeToString())
log.info('Finished image {:s}'.format(key))
writer.close()