def _setup_regression_predictions_and_loss(self):
self.training_end_points = self.model(is_training=True, reuse=None)
self.inputs = self.training_end_points['inputs']
self.training_predictions = self.training_end_points['predictions']
self.validation_end_points = self.model(is_training=False, reuse=True)
self.validation_inputs = self.validation_end_points['inputs']
self.validation_predictions = self.validation_end_points['predictions']
with tf.name_scope('predictions'):
self.target = tf.placeholder(tf.float32, shape=(None, 1), name='target')
with tf.name_scope('loss'):
training_loss = tf.reduce_mean(
tf.square(tf.subtract(self.training_predictions, self.target)))
self.validation_loss = tf.reduce_mean(
tf.square(tf.subtract(self.validation_predictions, self.target)))
l2_loss = tf.add_n(tf.get_collection(tf.GraphKeys.REGULARIZATION_LOSSES))
self.regularized_training_loss = training_loss + l2_loss * self.cnf.get('l2_reg', 0.0)
评论列表
文章目录