def setUp(self):
# Set up model
tf.reset_default_graph()
X = tf.placeholder(tf.float32, shape=[None, 784])
y = tf.placeholder(tf.float32, shape=[None, 10])
W_fc1 = weight_variable([784, 1024])
b_fc1 = bias_variable([1024])
h_fc1 = tf.nn.relu(tf.matmul(X, W_fc1) + b_fc1)
W_fc2 = weight_variable([1024, 10])
b_fc2 = bias_variable([10])
h_fc2 = tf.nn.softmax(tf.matmul(h_fc1, W_fc2) + b_fc2)
losses = -tf.reduce_sum(y*tf.log(h_fc2), reduction_indices=[1])
self.loss = tf.reduce_mean(losses)
self.batch_size = tf.cast(tf.gather(tf.shape(losses), 0), tf.float32)
self.var_list = [W_fc1, b_fc1, W_fc2, b_fc2]
self.X = X
self.y = y
self.sess = tf.Session()
self.sess.run(tf.initialize_all_variables())
self.mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)
test_gradient_moment.py 文件源码
python
阅读 34
收藏 0
点赞 0
评论 0
评论列表
文章目录