0
私は多人数で、マルチ入力とマルチ出力の問題を解決するためにテンソルを使用しようとしました。しかし、トレーニングの過程で、ネットワークの重量とコストは変わりません。ここにいくつかのメインコードがありますが、どんな提案も感謝しています!テンソルフローのトレーニングで重みとコストが変わらない
learning_rate = 0.01
training_epoch = 2000
batch_size = 100
display_step = 1
# place holder for graph input
x = tf.placeholder("float64", [None, 14])
y = tf.placeholder("float64", [None, 8])
# model weights
w_1 = tf.Variable(tf.zeros([14, 11], dtype = tf.float64))
w_2 = tf.Variable(tf.zeros([11, 8], dtype = tf.float64))
# construct a model
h_in = tf.matmul(x, w_1)
h_out = tf.nn.relu(h_in)
o_in = tf.matmul(h_out, w_2)
o_out = tf.nn.relu(o_in)
# cost: mean square error
cost = tf.reduce_sum(tf.pow((o_out - y), 2))
# optimizer
optimizer = tf.train.GradientDescentOptimizer(learning_rate).minimize(cost)
# initializer
init = tf.global_variables_initializer()
# launch the graph
with tf.Session() as sess:
sess.run(init)
for epoch in range(training_epoch):
pos = 0;
# loop over all batches
if pos < train_input_array.shape[0]:
# get the next batch
batch_i = []
batch_o = []
for i in range(pos, pos + batch_size):
batch_i.append(train_input_array[i].tolist())
batch_o.append(train_output_array[i].tolist())
np.array(batch_i)
np.array(batch_o)
pos += batch_size;
sess.run(optimizer, feed_dict = {x: batch_i, y: batch_o})
print sess.run(w_2[0])
if (epoch + 1) % display_step == 0:
c = sess.run(cost, feed_dict = {x: batch_i, y: batch_o})
print("Epoch: ", "%04d" % (epoch + 1), "cost: ", "{:.9f}".format(c))
reduce_meanし、あなたの費用関数を変更する必要があると思いますが、損失はまだ変更されません。 – Dennis
あなたはmomentmオプティマイザとより多くのパラメータを試してみるかもしれません –
あなたの提案をありがとう、私はtf.zeroからtf.random_normalに重み変数の初期化子を変更しました。 – Dennis