I'm beginner of tensorflow. I made simple autoencoder with the help. Next, I try to use test data in my model. I want to calculate loss value of test data for each train step.
Is my program correct? I afraid I renew weight and bias parameter with test process in my program. and what code did backpropagation process in 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)