def _setup_classification_predictions_and_loss(self):
self.inputs, self.target = self.input_queue.dequeue()
self.num_batch_elems = tf.size(self.target)
self.inputs = tf.reshape(self.inputs, self.input_shape)
self.training_end_points = self.model(is_training=True, reuse=None, inputs=self.inputs)
training_logits, self.training_predictions = self.training_end_points['logits'], self.training_end_points[
'predictions']
self.validation_end_points = self.model(is_training=False, reuse=True, inputs=self.inputs)
validation_logits, self.validation_predictions = self.validation_end_points['logits'], \
self.validation_end_points[
'predictions']
with tf.name_scope('loss'):
training_loss = tf.reduce_mean(
tf.nn.sparse_softmax_cross_entropy_with_logits(
logits=training_logits, labels=self.target))
self.validation_loss = tf.reduce_mean(
tf.nn.sparse_softmax_cross_entropy_with_logits(
logits=validation_logits, labels=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)
评论列表
文章目录