每个列车步骤的自动加速器测试值

时间:2016-12-19 07:14:19

标签: python machine-learning tensorflow autoencoder

我是张量流的初学者。我帮忙做了简单的自动编码器。接下来,我尝试在我的模型中使用测试数据。我想计算每个列车步骤的测试数据的损失值。

我的程序是否正确? 我担心在我的程序中用测试过程更新重量和偏差参数。 什么代码在tensorflow中做了反向传播过程?

image_side_size = 9
image_size = image_side_size * image_side_size * image_side_size
hidden  = 100
learn_data_size = 5000
test_data_size = 1000

# Variables
x_placeholder = tf.placeholder("float", (image_size))
x = tf.reshape(x_placeholder, [image_size, 1])

w_en = tf.Variable(tf.random_normal([hidden, image_size],mean=0.0,stddev = 0.05,name='w_en'))
w_de = tf.Variable(tf.random_normal([image_size, hidden],mean=0.0,stddev = 0.05,name='w_de'))
b_en = tf.Variable(tf.random_normal([hidden, 1],mean=0.0,stddev = 0.05,name='b_en'))
b_de = tf.Variable(tf.random_normal([image_size, 1],mean=0.0,stddev = 0.05,name='b_de'))

#model
en = tf.nn.sigmoid(tf.add(tf.matmul(w_en, x),b_en))
de = tf.nn.sigmoid(tf.add(tf.matmul(w_de,en),b_de))


# Cost Function
loss = tf.reduce_mean(tf.pow(de - x,2))
train_step = tf.train.AdagradOptimizer(0.01).minimize(loss)

with tf.Session() as sess:
sess.run(init)
print('Training...')
for j in range (100):
    for i in range(learn_data_size):
        loss_val, i = sess.run([loss,train_step], feed_dict = {x_placeholder: input_data})
        print(loss_val)

    for i in range(test_data_size):
        test_loss = sess.run(loss, feed_dict = {x_placeholder: test_data})
        print(test_loss)

0 个答案:

没有答案