2017-08-03 2 views
0

私は現在、自分のnnから予測をしようとしていますが、私はいつもnnの重みをどれだけ取り終えるのかわかりません。テンソルフローの低いレベルの予測をする

def neural_network_modelv2(data): 
    # (input_data * weights) +biases 
    hidden_1_layer = {'weights': tf.Variable(tf.random_normal([4, n_nodes_hl1])), 
         'biases': tf.Variable(tf.random_normal([n_nodes_hl1]))} 

    hidden_2_layer = {'weights': tf.Variable(tf.random_normal([n_nodes_hl1, n_nodes_hl2])), 
         'biases': tf.Variable(tf.random_normal([n_nodes_hl2]))} 

    hidden_3_layer = {'weights': tf.Variable(tf.random_normal([n_nodes_hl2, n_nodes_hl3])), 
         'biases': tf.Variable(tf.random_normal([n_nodes_hl3]))} 

    output_layer = {'weights': tf.Variable(tf.random_normal([n_nodes_hl3, n_classes])), 
        'biases': tf.Variable(tf.random_normal([n_classes])), } 
    data = tf.cast(data, tf.float32) 
    l1 = tf.add(tf.matmul(data, hidden_1_layer['weights']), hidden_1_layer['biases']) 
    l1 = tf.nn.relu(l1) 

    l2 = tf.add(tf.matmul(l1, hidden_2_layer['weights']), hidden_2_layer['biases']) 
    l2 = tf.nn.relu(l2) 

    l3 = tf.add(tf.matmul(l2, hidden_3_layer['weights']), hidden_3_layer['biases']) 
    l3 = tf.nn.relu(l3) 

    output_layer = tf.matmul(l3, output_layer['weights']) + output_layer['biases'] 

    return output_layer 

def train_modelv2(training_data, model=False): 
    x = tf.placeholder('float') 
    y = tf.placeholder('float') 

    trainingX = np.array([i[0] for i in training_data]).reshape(-1, len(training_data[0][0])) 
    trainingY = [i[1] for i in training_data] 


    nn = neural_network_modelv2(trainingX) 
    mn = tf.nn.softmax_cross_entropy_with_logits(logits=nn, labels=y) 
    cost = tf.reduce_mean(mn) 
    optimizer = tf.train.AdamOptimizer().minimize(cost) 

    hm_epochs = 10 

    with tf.Session() as sess: 

     sess.run(tf.initialize_all_variables()) 

     # Train 
     for epoch in range(hm_epochs): 
      epoch_loss = 0 
      ca, c = sess.run([optimizer, cost], feed_dict={x: trainingX, y: trainingY}) 
      epoch_loss += c 
     print('Training done') 

私は次のコードで予測を取得しようとするが、それが動作しません:

prediction = (sess.run([nn], feed_dict={x: prev_obs.reshape(-1, len(prev_obs))})[0]) 

あなたがここにhttps://pastebin.com/iGZHZuN8を完全なコードを確認することができ、あなたが必要

+0

実際には使用されていません'x'をあなたのネットワークのどこにでも置くことができます。 – jdehesa

答えて

0

を実行するために、その準備ができてneural_network_modelv2関数の入力としてプレースホルダを使用する

# replace the following line 
nn = neural_network_modelv2(trainingX) 
# with 
nn = neural_network_modelv2(x) 
関連する問題