简体   繁体   English

Tensorflow - ValueError:Shape必须为1,但对于'ParseExample / ParseExample'为0

[英]Tensorflow - ValueError: Shape must be rank 1 but is rank 0 for 'ParseExample/ParseExample'

I have a .tfrecords file of the Ubuntu Dialog Corpus. 我有一个Ubuntu Dialog Corpus的.tfrecords文件。 I am trying to read in the whole dataset so that I can split the contexts and utterances into batches. 我试图读取整个数据集,以便我可以将上下文和话语分成批次。 Using tf.parse_single_example I was able to read in a single example. 使用tf.parse_single_example我能够读到一个例子。 I tried using tf.parse_example but I get the following error 我尝试使用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].

I am not sure what to make of it. 我不知道该怎么做。 The code I used to get to the error - 我用来获取错误的代码 -

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)
})

Any ideas 有任何想法吗

to use tf.parse_example you need to first batch the examples: 要使用tf.parse_example,您需要先批量示例:

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

I had a similar problem just now. 我刚才有类似的问题。 Try putting brackets around the serialized_example to turn it into a list: 尝试在serialized_example周围放置括号以将其转换为列表:

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)
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TensorFlow 推荐者 - ValueError:形状必须为 2 级,但为 3 级 - TensorFlow Recommenders - ValueError: Shape must be rank 2 but is rank 3 Tensorflow:ValueError:Shape必须是等级2,但是等级3 - Tensorflow : ValueError: Shape must be rank 2 but is rank 3 Tensorflow: ValueError: Shape must be rank 4 but is rank 5 - Tensorflow: ValueError: Shape must be rank 4 but is rank 5 Tensorflow:optimizer.minimize()-“ ValueError:形状必须为0级,但为1级 - Tensorflow: optimizer.minimize() - "ValueError: Shape must be rank 0 but is rank 1 Tensorflow Shape必须为1级但为2级 - Tensorflow Shape must be rank 1 but is rank 2 ValueError:形状必须为 2 级,但“MatMul”为 1 级 - ValueError: Shape must be rank 2 but is rank 1 for 'MatMul' ValueError:Shape必须是2级,但是'MatMul'的排名是3 - ValueError: Shape must be rank 2 but is rank 3 for 'MatMul' TensorFlow - 切片张量导致:ValueError: Shape (16491,) must have rank 3 - TensorFlow - Slicing tensor results in: ValueError: Shape (16491,) must have rank 3 使用LSTM RNN在tensorflow中进行分类,ValueError:Shape(1、10、5)必须具有等级2 - classification with LSTM RNN in tensorflow, ValueError: Shape (1, 10, 5) must have rank 2 Tensorflow LSTM抛出ValueError:Shape()的等级必须至少为2 - Tensorflow LSTM throws ValueError: Shape () must have rank at least 2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM