2017-08-04 8 views
0

このテンソルフローコードは応答していません。理由はわかりません。助けてください!Tensorflowは無限ループに終わります

import tensorflow as tf 
#reading the file 
with tf.name_scope ('File_reading') as scope: 
    filename_queue = tf.train.string_input_producer(["forestfires.csv.digested"]) 
    reader = tf.TextLineReader() 
    key, value = reader.read(filename_queue) 
    record_defaults = [[1.0], [1.0], [1.0], [1.0], [1.0], [1.0], [1.0], [1.0], [1.0], [1.0], [1.0], [1.0], [0.0]] 
    #13 decoded 
    col1, col2, col3, col4, col5, col6, col7, col8, col9, col10, col11, col12, col13 = tf.decode_csv(
     value, record_defaults=record_defaults) 


    #12 is feture, and the 13th is the training data 
    features = tf.stack([col1, col2, col3, col4, col5, col6, col7, col8, col9, col10, col11, col12],name='data_input') 

    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(517): 
      # Retrieve a single instance: 
      example, label = sess.run([features, col13]) 

     coord.request_stop() 
     coord.join(threads) 
with tf.name_scope ('network') as scope: 
    W1=tf.Variable(tf.zeros([12, 8]), name='W1') 
    b1=tf.Variable(tf.zeros([8]), name="b1") 
    h1=tf.add(tf.matmul(tf.expand_dims(features,0), W1),b1, name='hidden_layer') 
    W2=tf.Variable(tf.zeros([8, 1]), name='W2') 
    b2=tf.Variable(tf.zeros([1]), name="b2") 
    output=tf.add(tf.matmul(h1, W2),b2, name='output_layer') 
error=tf.add(output,-col13, name='error') 
#training 
train_step = tf.train.AdamOptimizer(1e-4).minimize(error) 
#graphing the output 
file_writer = tf.summary.FileWriter('some directory', sess.graph) 
with tf.Session() as sess: 
    #init 
    tf.global_variables_initializer().run() 
    print ("\n\n\n\n\n\nTRAINING STARTED\n\n\n\n\n\n") 
    print('test1') 
    sess.run(error) #this statement causes an infinite loop 
    print ('test2') 
file_writer.close() 

コードが実行され、 'test1'が表示されますが、それでもCtrl + Cには反応しません。私は問題を調べようとしましたが、私のGoogleスキルが十分ではないか、インターネット上にないのです。 システム:win10 geforce 960M python 3.5.2

答えて

0

あなたがネットワークを構築した方法は、知的には意味がありません。 TextLineReaderから517ステップを読み込む必要がある場合は、read_up_to関数を使用し、別々のセッションを使用するのではなく、517の値を指定します。あなたがグラフを作成したやり方では、入力リーダーとグラフの残りの部分との間にきちんと接続されているようには見えません。

私の提案:

# define graph which includes the input queue 
def model(...): 
... 
    return error, metrics 

with tf.Graph.as_default(): 
    error, metrics = model(...) 

    with tf.Session(): 
    # Start Coordinator 
    # Initialise global vars 
    # Start queue runners 
    # model_error, model_metrics = sess.run([error, metrics]) 
0

は(このバグのために)それを解決、それはそれだけで入力されたデータを待って、無限ループではなかったです。なんらかの理由で、tf.Session()をsess: 'としてアッパーを貼り付けると、ブロックの下端の上部にブロックが付いているので、うまく動作します。 (私はそれ以来、いくつかの点を変更しているので、他のコーディングエラーがある可能性があります)

関連する問題