微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

python – Tensorflow – ValueError:Shape必须为1,但对于’ParseExample / ParseExample’为0

我有一个Ubuntu Dialog Corpus的.tfrecords文件.我试图读取整个数据集,以便我可以将上下文和话语分成批次.使用tf.parse_single_example我能够读到一个例子.我尝试使用tf.parse_example,但是我收到以下错误

ValueError: Shape must be rank 1 but is rank 0 for 'ParseExample/ParseExample' (op: 'ParseExample') with input shapes: [], [0], [], [], [], [], [], [0], [0], [0], [0], [0].

我不知道该怎么做.我用来获取错误代码

import tensorflow as tf    
TRAIN_FILE_TFREC = 'data/train.tfrecords'

filename_queue = tf.train.string_input_producer([TRAIN_FILE_TFREC])

reader = tf.TFRecordReader()
_, serialized_example = reader.read(filename_queue)

features = tf.parse_example(serialized_example, 
features = {
"context" : tf.FixedLenFeature([160], tf.int64),
"context_len" : tf.FixedLenFeature([1], tf.int64),
"utterance" : tf.FixedLenFeature([80], tf.int64),
"utterance_len" : tf.FixedLenFeature([1], tf.int64),
"label" : tf.FixedLenFeature([1], tf.int64)
})

有任何想法吗

解决方法:

要使用tf.parse_example,您需要先批量示例:

batch = tf.train.batch([serialized_example], num_examples, capacity=num_examples)
parsed_examples = tf.parse_example(batch, feature_spec)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐