簡體   English   中英

Tensorflow - ValueError:Shape必須為1,但對於'ParseExample / ParseExample'為0

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

我有一個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)

我剛才有類似的問題。 嘗試在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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM