def __init__(self, name):
with tf.variable_scope('inv') as scope:
self.true_label = tf.placeholder(tf.float32, [N_BATCH, X_L], name="true_label_"+name)
self.observations = tf.placeholder(tf.float32, [N_BATCH, L, L, 2], name="obs_"+name)
self.n_hidden = 1200
W_inv1 = weight_variable([L*L*2, self.n_hidden], name="W_inv1_"+name)
b_inv1 = bias_variable([self.n_hidden], name="b_inv1_"+name)
W_inv2 = weight_variable([self.n_hidden,X_L], name="W_inv2_"+name)
b_inv2 = bias_variable([X_L], name="b_inv2_"+name)
self.VARS = [W_inv1, b_inv1, W_inv2, b_inv2]
reshape_ob = tf.reshape(self.observations, [N_BATCH, L*L*2])
blah = tf.nn.relu(tf.matmul(reshape_ob, W_inv1) + b_inv1)
epsilon1 = tf.constant(1e-10, shape=[N_BATCH, X_L])
self.pred = tf.nn.softmax(tf.matmul(blah, W_inv2) + b_inv2) + epsilon1
self.cost = -tf.reduce_sum(self.true_label * tf.log(self.pred))
optimizer = tf.train.RMSPropOptimizer(0.001)
inv_gvs = optimizer.compute_gradients(self.cost)
self.train_inv = optimizer.apply_gradients(inv_gvs)
all_var_var = tf.get_collection(tf.GraphKeys.VARIABLES, scope='inv')
self.init = tf.initialize_variables(all_var_var)
self.saver = tf.train.Saver(self.VARS)
# train on a particular data batch
model.py 文件源码
python
阅读 24
收藏 0
点赞 0
评论 0
评论列表
文章目录