def add_loss_op(self, target):
self.target = target # for outputting later
real_target = tf.abs(self.target)
# mean = tf.concat([stats[0][0], stats[0][1]])
# stdev = tf.concat([stats[1][0], stats[1][1]])
# print(mean.get_shape())
# print(stdev.get_shape())
# real_target -= mean
# real_target /= stdev
delta = self.output - real_target
squared_error = tf.reduce_mean(tf.pow(delta, 2))
l2_cost = tf.reduce_mean([tf.norm(v) for v in tf.trainable_variables() if len(v.get_shape().as_list()) == 3])
self.loss = Config.l2_lambda * l2_cost + squared_error
tf.summary.scalar("loss", self.loss)
masked_loss = tf.abs(self.soft_masked_output) - real_target
self.masked_loss = Config.l2_lambda * l2_cost + tf.reduce_mean(tf.pow(masked_loss, 2))
tf.summary.scalar('masked_loss', self.masked_loss)
tf.summary.scalar('regularization_cost', Config.l2_lambda * l2_cost)
评论列表
文章目录