【发布时间】:2019-08-08 15:33:26
【问题描述】:
那些天我在运行代码读取“tfrecords”数据时遇到了这个错误。问题是如何找到“具有 71680 个值的张量”或“形状有 8960”?
错误是:
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.我读取“tfrecords”数据的代码在这里:
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
我认为关键在images = tf.decode_raw(features['image_raw'],tf.uint8),但我不知道为什么以及如何。这里我给出我的代码来制作“tfrecords”数据。
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()
当我使用PIL.Image 替换cv2 时,它可以工作!这里的图像 high=32,width=280 。有人知道为什么会发生在cv2 吗?或者如何以正确的方式从tfrecords 数据中读取图像。
【问题讨论】:
-
请编辑这篇文章以包含
crnn的样子。 -
对不起,我没有明白我的错误的重点。这里我详细重写我的错误地方
标签: python tensorflow