(
self,
model,
input_record,
name='batch_lr_loss',
average_loss=True,
jsd_weight=0.0,
pos_label_target=1.0,
neg_label_target=0.0,
homotopy_weighting=False,
log_D_trick=False,
unjoined_lr_loss=False,
uncertainty_penalty=1.0,
focal_gamma=0.0,
stop_grad_in_focal_factor=False,
task_gamma=1.0,
task_gamma_lb=0.1,
**kwargs
)
| 17 | |
| 18 | class BatchLRLoss(ModelLayer): |
| 19 | def __init__( |
| 20 | self, |
| 21 | model, |
| 22 | input_record, |
| 23 | name='batch_lr_loss', |
| 24 | average_loss=True, |
| 25 | jsd_weight=0.0, |
| 26 | pos_label_target=1.0, |
| 27 | neg_label_target=0.0, |
| 28 | homotopy_weighting=False, |
| 29 | log_D_trick=False, |
| 30 | unjoined_lr_loss=False, |
| 31 | uncertainty_penalty=1.0, |
| 32 | focal_gamma=0.0, |
| 33 | stop_grad_in_focal_factor=False, |
| 34 | task_gamma=1.0, |
| 35 | task_gamma_lb=0.1, |
| 36 | **kwargs |
| 37 | ): |
| 38 | super().__init__(model, name, input_record, **kwargs) |
| 39 | |
| 40 | self.average_loss = average_loss |
| 41 | |
| 42 | assert (schema.is_schema_subset( |
| 43 | schema.Struct( |
| 44 | ('label', schema.Scalar()), |
| 45 | ('logit', schema.Scalar()) |
| 46 | ), |
| 47 | input_record |
| 48 | )) |
| 49 | |
| 50 | self.jsd_fuse = False |
| 51 | assert jsd_weight >= 0 and jsd_weight <= 1 |
| 52 | if jsd_weight > 0 or homotopy_weighting: |
| 53 | assert 'prediction' in input_record |
| 54 | self.init_weight(jsd_weight, homotopy_weighting) |
| 55 | self.jsd_fuse = True |
| 56 | self.homotopy_weighting = homotopy_weighting |
| 57 | |
| 58 | assert pos_label_target <= 1 and pos_label_target >= 0 |
| 59 | assert neg_label_target <= 1 and neg_label_target >= 0 |
| 60 | assert pos_label_target >= neg_label_target |
| 61 | self.pos_label_target = pos_label_target |
| 62 | self.neg_label_target = neg_label_target |
| 63 | |
| 64 | assert not (log_D_trick and unjoined_lr_loss) |
| 65 | self.log_D_trick = log_D_trick |
| 66 | self.unjoined_lr_loss = unjoined_lr_loss |
| 67 | assert uncertainty_penalty >= 0 |
| 68 | self.uncertainty_penalty = uncertainty_penalty |
| 69 | |
| 70 | self.tags.update([Tags.EXCLUDE_FROM_PREDICTION]) |
| 71 | |
| 72 | self.output_schema = schema.Scalar( |
| 73 | np.float32, |
| 74 | self.get_next_blob_reference('output') |
| 75 | ) |
| 76 |
nothing calls this directly
no test coverage detected