Exemplo n.º 1
0
 def create_loss(self, input_dict=None):
     if self.loss_flag == 0:
         loss = CrossEntropy2d(ignore_index=250)
         self.add_block_list(LossType.CrossEntropy2d, loss,
                             self.block_out_channels[-1])
         self.lossList.append(loss)
     elif self.loss_flag == 1:
         loss = CrossEntropy2d(ignore_index=250)
         self.add_block_list(LossType.CrossEntropy2d, loss,
                             self.block_out_channels[-1])
         self.lossList.append(loss)
Exemplo n.º 2
0
 def __init__(self, num_class,
              se_loss=False, se_weight=0.2,
              aux=False, aux_weight=0.4,
              weight=None, reduction='mean', ignore_index=250):
     super().__init__(LossType.EncNetLoss)
     self.num_class = num_class
     self.se_loss = se_loss
     self.aux = aux
     self.se_weight = se_weight
     self.aux_weight = aux_weight
     self.ce = CrossEntropy2d(0, weight, True,
                              reduction, ignore_index)
     self.bce = BinaryCrossEntropy2d(0, weight, True,
                                     reduction, ignore_index)
Exemplo n.º 3
0
 def create_loss(self, module_def):
     if module_def['type'] == LossType.YoloLoss:
         anchor_idxs = [int(x) for x in module_def['mask'].split(',')]
         # Extract anchors
         anchors = [float(x) for x in module_def['anchors'].split(',')]
         anchors = [(anchors[i], anchors[i + 1]) for i in range(0, len(anchors), 2)]
         num_classes = int(module_def['classes'])
         # Define detection layer
         yolo_layer = YoloLoss(num_classes, anchors=anchors,
                               anchors_mask=anchor_idxs, smoothLabel=False,
                               focalLoss=False)
         self.addBlockList(LossType.YoloLoss, yolo_layer, self.filters)
         self.input_channels = self.filters
     elif module_def["type"] == LossType.CrossEntropy2d:
         weight_type = int(module_def.get("weight_type", 0))
         weight = module_def.get("weight", None)
         reduce = module_def.get("reduce", None)
         reduction = module_def.get("reduction", 'mean')
         ignore_index = int(module_def.get("ignore_index", 250))
         layer = CrossEntropy2d(weight_type=weight_type,
                                weight=weight,
                                reduce=reduce,
                                reduction=reduction,
                                ignore_index=ignore_index)
         self.addBlockList(LossType.CrossEntropy2d, layer, self.filters)
         self.input_channels = self.filters
     elif module_def["type"] == LossType.OhemCrossEntropy2d:
         ignore_index = int(module_def.get("ignore_index", 250))
         layer = OhemCrossEntropy2d(ignore_index=ignore_index)
         self.addBlockList(LossType.OhemCrossEntropy2d, layer, self.filters)
         self.input_channels = self.filters
     elif module_def["type"] == LossType.BinaryCrossEntropy2d:
         weight_type = int(module_def.get("weight_type", 0))
         weight = module_def.get("weight", None)
         reduce = module_def.get("reduce", None)
         reduction = module_def.get("reduction", 'mean')
         layer = BinaryCrossEntropy2d(weight_type=weight_type,
                                      weight=weight,
                                      reduce=reduce,
                                      reduction=reduction)
         self.addBlockList(LossType.BinaryCrossEntropy2d, layer, self.filters)
         self.input_channels = self.filters