def _setup_training(self):
"""
Set up a data flow graph for fine tuning
"""
layer_num = self.layer_num
act_func = ACTIVATE_FUNC[self.activate_func]
sigma = self.sigma
lr = self.learning_rate
weights = self.weights
biases = self.biases
data1, data2 = self.data1, self.data2
batch_size = self.batch_size
optimizer = OPTIMIZER[self.optimizer]
with tf.name_scope("training"):
s1 = self._obtain_score(data1, weights, biases, act_func, "1")
s2 = self._obtain_score(data2, weights, biases, act_func, "2")
with tf.name_scope("cost"):
sum_cost = tf.reduce_sum(tf.log(1 + tf.exp(-sigma*(s1-s2))))
self.cost = cost = sum_cost / batch_size
self.optimize = optimizer(lr).minimize(cost)
for n in range(layer_num-1):
tf.histogram_summary("weight"+str(n), weights[n])
tf.histogram_summary("bias"+str(n), biases[n])
tf.scalar_summary("cost", cost)
评论列表
文章目录