def mlp(x, y):
op_list = list()
op_list.append(x)
w_input = tf.Variable(tf.truncated_normal([n_input, n_hidden], stddev=0.1))
b_input = tf.Variable(tf.constant(0., shape=[n_hidden]))
op_list.append(tf.matmul(op_list[-1], w_input) + b_input)
for i in range(n_h_layer):
w = tf.Variable(tf.truncated_normal([n_hidden, n_hidden], stddev=0.1))
b = tf.Variable(tf.constant(0., shape=[n_hidden]))
op_list.append(tf.matmul(op_list[-1], w) + b)
w_output = tf.Variable(tf.truncated_normal([n_hidden, n_output], stddev=0.1))
b_output = tf.Variable(tf.constant(0., shape=[n_output]))
op_list.append(tf.matmul(op_list[-1], w_output) + b_output)
loss = tf.nn.l2_loss(tf.sub(op_list[-1], y))
return op_list[-1], loss
评论列表
文章目录