2017-05-04 12 views
3

我試圖從https://www.tensorflow.org/programmers_guide/reading_data 運行示例, :TensorFlow - decode_csv:期望3個字段,但在記錄0中有5個,當給出5個默認值時拋出:期望5個字段,但在記錄0中有3個

example_data.txt

DESC|manner|How did serfdom develop in and then leave Russia ? 
ENTY|cremat|What films featured the character Popeye Doyle ? 
DESC|manner|How can I find a list of celebrities ' real names ? 
ENTY|animal|What fowl grabs the spotlight after the Chinese Year of the Monkey ? 
             more... 

TensorFlow代碼:

import numpy as np 
import tensorflow as tf 

filename_queue = tf.train.string_input_producer(["example_data.txt"]) 
reader = tf.TextLineReader() 
key, value = reader.read(filename_queue) 

record_defaults = [['hello'], ['hello'], ['hello']] 
col1, col2, col3 = tf.decode_csv(
    value, record_defaults=record_defaults, field_delim="|") 
features = tf.stack([col1, col2, col3]) 

print(features) 

with tf.Session() as sess: 
    # Start populating the filename queue. 
    coord = tf.train.Coordinator() 
    threads = tf.train.start_queue_runners(coord=coord) 

    for i in range(1200): 
    # Retrieve a single instance: 
    example, label = sess.run([features, col2]) 

    coord.request_stop() 
    coord.join(threads) 

這引發錯誤: Expect 3 fields but have 5 in record 0

,但如果我改變:

record_defaults = [['hello'], ['hello'], ['hello'], ['hello'], ['hello']] 
    col1, col2, col3, col4, col5 = tf.decode_csv(
     value, record_defaults=record_defaults, field_delim="|") 

這將引發一個錯誤: Expect 5 fields but have 3 in record 0

這是怎麼回事?這是TensorFlow中的一個錯誤嗎?

回答

1

當使用tf.decode_csvtf.TextLineReader時,僅僅在文件末尾存在空行會導致類似的錯誤'期望5個字段,但在記錄0中有0'。

同樣,您可能希望查看數據文件以查看是否有任何問題,即使它與「空白行」一樣微不足道。

相關問題