nn/basicNetwork.py
def make_loss(self, label, loss_type='xent'):
        """
        Make loss to optimize for the network
        :param label: input labels, can be generated by tf.data.Dataset
        :param loss_type:
            xent: cross entropy loss
        :return:
        """
        with tf.variable_scope('loss'):
            pred_flat = tf.reshape(self.pred, [-1, self.class_num])
            y_flat = tf.reshape(tf.squeeze(label, axis=[3]), [-1, ])
            indices = tf.squeeze(tf.where(tf.less_equal(y_flat, self.class_num - 1)), 1)
            gt = tf.gather(y_flat, indices)
            prediction = tf.gather(pred_flat, indices)

            pred = tf.argmax(prediction, axis=-1, output_type=tf.int32)
            self.loss_iou = self.create_resetable_metric(tf.metrics.mean_iou, var_name='loss_iou',
                                                         scope=tf.get_variable_scope().name,
                                                         labels=gt, predictions=pred, num_classes=self.class_num,
                                                         name='loss_iou')

            if loss_type == 'xent':
                self.loss = tf.reduce_mean(tf.nn.sparse_softmax_cross_entropy_with_logits(logits=prediction, labels=gt))
                self.loss_xent = self.create_resetable_metric(tf.metrics.mean, var_name='loss_xent',
                                                              scope=tf.get_variable_scope().name,
                                                              values=self.loss, name='loss_xent')
            else:
                # TODO focal loss:
                # https://github.com/ailias/Focal-Loss-implement-on-Tensorflow/blob/master/focal_loss.py
                self.loss = None

        Make loss to optimize for the network
        :param label: input labels, can be generated by tf.data.Dataset
        :param loss_type:
            xent: cross entropy loss
        :return:
        
Make loss to optimize for the network
Make loss to optimize for the network
def make_loss(self, label, loss_type='xent'):
        with tf.variable_scope('loss'):
            pred_flat = tf.reshape(self.pred, [-1, self.class_num])
            y_flat = tf.reshape(tf.squeeze(label, axis=[3]), [-1, ])
            indices = tf.squeeze(tf.where(tf.less_equal(y_flat, self.class_num - 1)), 1)
            gt = tf.gather(y_flat, indices)
            prediction = tf.gather(pred_flat, indices)
            pred = tf.argmax(prediction, axis=-1, output_type=tf.int32)
            self.loss_iou = self.create_resetable_metric(tf.metrics.mean_iou, var_name='loss_iou',
                                                         scope=tf.get_variable_scope().name,
                                                         labels=gt, predictions=pred, num_classes=self.class_num,
                                                         name='loss_iou')
            if loss_type == 'xent':
                self.loss = tf.reduce_mean(tf.nn.sparse_softmax_cross_entropy_with_logits(logits=prediction, labels=gt))
                self.loss_xent = self.create_resetable_metric(tf.metrics.mean, var_name='loss_xent',
                                                              scope=tf.get_variable_scope().name,
                                                              values=self.loss, name='loss_xent')
            else:
                self.loss = None
def make_loss ( self , label , loss_type = 'xent' ) : with tf . variable_scope ( 'loss' ) : pred_flat = tf . reshape ( self . pred , [ - 1 , self . class_num ] ) y_flat = tf . reshape ( tf . squeeze ( label , axis = [ 3 ] ) , [ - 1 , ] ) indices = tf . squeeze ( tf . where ( tf . less_equal ( y_flat , self . class_num - 1 ) ) , 1 ) gt = tf . gather ( y_flat , indices ) prediction = tf . gather ( pred_flat , indices ) pred = tf . argmax ( prediction , axis = - 1 , output_type = tf . int32 ) self . loss_iou = self . create_resetable_metric ( tf . metrics . mean_iou , var_name = 'loss_iou' , scope = tf . get_variable_scope ( ) . name , labels = gt , predictions = pred , num_classes = self . class_num , name = 'loss_iou' ) if loss_type == 'xent' : self . loss = tf . reduce_mean ( tf . nn . sparse_softmax_cross_entropy_with_logits ( logits = prediction , labels = gt ) ) self . loss_xent = self . create_resetable_metric ( tf . metrics . mean , var_name = 'loss_xent' , scope = tf . get_variable_scope ( ) . name , values = self . loss , name = 'loss_xent' ) else : self . loss = None
Make loss to optimize for the network
Make loss to optimize for the network
"""
        Make loss to optimize for the network
        :param label: input labels, can be generated by tf.data.Dataset
        :param loss_type:
            xent: cross entropy loss
        :return:
        """ # TODO focal loss: # https://github.com/ailias/Focal-Loss-implement-on-Tensorflow/blob/master/focal_loss.py
None
self
label
input labels, can be generated by tf.data.Dataset
input labels can be generated by tf . data . Dataset
loss_type
cross entropy loss
cross entropy loss