def __init__(self, config: ScalarModelBase, *args: Any, **kwargs: Any) -> None: super().__init__(config, *args, **kwargs) self.model = config.create_model() raw_loss = model_util.create_scalar_loss_function(config) if isinstance(config, SequenceModelBase): self.loss_fn = lambda model_output, loss: apply_sequence_model_loss( raw_loss, model_output, loss) self.target_indices = config.get_target_indices() self.target_names = [ SequenceMetricsDict.get_hue_name_from_target_index(p) for p in config.sequence_target_positions ] else: self.loss_fn = raw_loss self.target_indices = [] self.target_names = config.class_names self.is_classification_model = config.is_classification_model self.use_mean_teacher_model = config.compute_mean_teacher_model self.is_binary_classification_or_regression = True if len( config.class_names) == 1 else False self.logits_to_posterior_fn = config.get_post_loss_logits_normalization_function( ) self.loss_type = config.loss_type # These two fields store the PyTorch Lightning Metrics objects that will compute metrics on validation # and training set, in particular ones that are not possible to compute from a single minibatch (AUC and alike) self.train_metric_computers = self.create_metric_computers() self.val_metric_computers = self.create_metric_computers()
def __init__(self, config: ScalarModelBase, *args: Any, **kwargs: Any) -> None: super().__init__(config, *args, **kwargs) self.model = config.create_model() raw_loss = model_util.create_scalar_loss_function(config) self.loss_fn = raw_loss self.target_names = config.target_names self.is_classification_model = config.is_classification_model self.use_mean_teacher_model = config.compute_mean_teacher_model self.is_binary_classification_or_regression = True if len( config.class_names) == 1 else False self.logits_to_posterior_fn = config.get_post_loss_logits_normalization_function( ) self.loss_type = config.loss_type # These two fields store the PyTorch Lightning Metrics objects that will compute metrics on validation # and training set, in particular ones that are not possible to compute from a single minibatch (AUC and alike) self.train_metric_computers = config.create_metric_computers() self.val_metric_computers = config.create_metric_computers() self.compute_and_log_metrics = config.compute_and_log_metrics