2017-01-24 4 views
0

現在TensorFlowを勉強中です。私は予測モデルを正確に評価してスコアを割り当てることができるNNを作成しようとしています。現在私の計画は、既存のプログラムのスコアを組み合わせて、それらを真の値と比較しながらmlpで実行することです。私はMNISTのデータを使って遊んだので、私が学んだことを自分のプロジェクトに適用しようとしています。残念ながら、私はコードがcross_entropyの行を実行しているときにこのエラーが発生しテンソルフローValueError:両方の図形の寸法0は同じでなければなりません

ValueError: Dimension 0 in both shapes must be equal, but are 9517 and 1 

私にこのエラーが問題

def multilayer_perceptron(x, w1): 
    # Hidden layer with RELU activation 
    layer_1 = tf.matmul(x, w1) 
    layer_1 = tf.nn.relu(layer_1) 
    # Output layer with linear activation 
    #out_layer = tf.matmul(layer_1, w2) 
    return layer_1 

def my_mlp (trainer, trainer_awn, learning_rate, training_epochs, n_hidden, n_input, n_output): 
trX, trY= trainer, trainer_awn 
#create placeholders 
x = tf.placeholder(tf.float32, shape=[9517, 5]) 
y_ = tf.placeholder(tf.float32, shape=[9517, ]) 
#create initial weights 
w1 = tf.Variable(tf.zeros([5, 1])) 
#predicted class and loss function 
y = multilayer_perceptron(x, w1) 
cross_entropy = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(y, y_)) 
#training 
train_step = tf.train.AdamOptimizer(learning_rate=learning_rate).minimize(cross_entropy) 
correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_,1)) 
with tf.Session() as sess: 
    # you need to initialize all variables 
    sess.run(tf.initialize_all_variables()) 
    print("1") 
    for i in range(training_epochs + 1): 
     sess.run([train_step], feed_dict={x: [trX['V7'], trX['V8'], trX['V9'], trX['V10'], trX['V12']], y_: trY}) 
return 

を与えてきました。私はこれがなぜあなたがそれを与えることを喜んで私はそれ以上の情報を必要としている場合、それはなぜか分かりません。

答えて

0

あなたの場合、yの形は[9517、1]、y_の形は[9517]です。彼らはcampatibleではありません。 tf.reshape(y_、[-1、1])を使用してy_の形を変えてみてください

+0

ありがとうございました! –

関連する問題