def __init__(self, in_channels, n_grps, N, num_classes, dropout, first_width, stride, dilation, learning_rate, ensemble_size, n_logit_samples, loss_weights=None, **kwargs): """ Initializes the ECGResNetEnsemble_AuxOutSystem Args: in_channels: number of channels of input n_grps: number of ResNet groups N: number of blocks per groups num_classes: number of classes of the classification problem dropout: probability of an argument to get zeroed in the dropout layer first_width: width of the first input stride: tuple with stride value per block per group dilation: spacing between the kernel points of the convolutional layers learning_rate: the learning rate of the model ensemble_size: the number of models that make up the ensemble n_logit_samples: number of logit samples of the auxiliary output loss_weights: array of weights for the loss term """ super().__init__() self.save_hyperparameters() self.learning_rate = learning_rate self.num_classes = num_classes self.ensemble_size = ensemble_size self.n_logit_samples = n_logit_samples self.IDs = torch.empty(0).type(torch.LongTensor) self.predicted_labels = torch.empty(0).type(torch.LongTensor) self.correct_predictions = torch.empty(0).type(torch.BoolTensor) self.epistemic_uncertainty = torch.empty(0).type(torch.FloatTensor) self.aleatoric_uncertainty = torch.empty(0).type(torch.FloatTensor) self.total_uncertainty = torch.empty(0).type(torch.FloatTensor) self.models = [] self.optimizers = [] for i in range(self.ensemble_size): self.models.append( ECGResNet_AuxOut(in_channels, n_grps, N, num_classes, dropout, first_width, stride, dilation)) if loss_weights is not None: weights = torch.tensor(loss_weights, dtype=torch.float) else: weights = loss_weights self.loss = FocalLoss(gamma=1, weights=weights)
def __init__(self, in_channels, n_grps, N, num_classes, dropout, first_width, stride, dilation, learning_rate, n_dropout_samples, sampling_dropout_rate, n_logit_samples, loss_weights=None, **kwargs): """ Args: in_channels: number of channels of input n_grps: number of ResNet groups N: number of blocks per groups num_classes: number of classes of the classification problem dropout: probability of an argument to get zeroed in the dropout layer first_width: width of the first input stride: tuple with stride value per block per group dilation: spacing between the kernel points of the convolutional layers learning_rate: the learning rate of the model n_dropout_samples: number of Monte Carlo dropout samples to take sampling_dropout_rate: the ratio of dropped-out neurons during Monte Carlo sampling n_logit_samples: number of logit samples of the auxiliary output loss_weights: array of weights for the loss term """ super().__init__() self.save_hyperparameters() self.learning_rate = learning_rate self.n_dropout_samples = n_dropout_samples self.n_logit_samples = n_logit_samples self.IDs = torch.empty(0).type(torch.LongTensor) self.predicted_labels = torch.empty(0).type(torch.LongTensor) self.correct_predictions = torch.empty(0).type(torch.BoolTensor) self.aleatoric_uncertainty = torch.empty(0).type(torch.FloatTensor) self.epistemic_uncertainty = torch.empty(0).type(torch.FloatTensor) self.total_uncertainty = torch.empty(0).type(torch.FloatTensor) self.model = ECGResNet_MCDropout_AuxOutput(in_channels, n_grps, N, num_classes, dropout, first_width, stride, dilation, n_dropout_samples, sampling_dropout_rate, n_logit_samples) if loss_weights is not None: weights = torch.tensor(loss_weights, dtype=torch.float) else: weights = loss_weights self.loss = FocalLoss(gamma=1, weights=weights)
def __init__(self, in_channels, n_grps, N, num_classes, dropout, first_width, stride, dilation, learning_rate, loss_weights=None, include_classification=True, **kwargs): """ Initializes the ECGResNetUncertaintySystem Args: in_channels: number of channels of input n_grps: number of ResNet groups N: number of blocks per groups num_classes: number of classes of the classification problem dropout: probability of an argument to get zeroed in the dropout layer first_width: width of the first input stride: tuple with stride value per block per group dilation: spacing between the kernel points of the convolutional layers learning_rate: the learning rate of the model loss_weights: array of weights for the loss term """ super().__init__() self.save_hyperparameters() self.learning_rate = learning_rate self.model = ECGResNet(in_channels, n_grps, N, num_classes, dropout, first_width, stride, dilation, include_classification) if loss_weights is not None: weights = torch.tensor(loss_weights, dtype=torch.float) else: weights = loss_weights self.loss = FocalLoss(gamma=1, weights=weights)
def __init__(self, in_channels, n_grps, N, num_classes, dropout, first_width, stride, dilation, learning_rate, n_weight_samples, kl_weighting_type, kl_weighting_scheme, max_epochs, train_dataset_size, val_dataset_size, batch_size, loss_weights=None, **kwargs): """ Initializes the ECGResNetVariationalInference_BayesianDecompositionSystem Args: in_channels: number of channels of input n_grps: number of ResNet groups N: number of blocks per groups num_classes: number of classes of the classification problem dropout: probability of an argument to get zeroed in the dropout layer first_width: width of the first input stride: tuple with stride value per block per group dilation: spacing between the kernel points of the convolutional layers learning_rate: the learning rate of the model n_weight_samples: number of Monte Carlo samples of the weights kl_weighting_type: which type of weighting to apply to the Kullback-Leibler term kl_weighting_scheme: which scheme of weighting to apply to the Kullback-Leibler term max_epochs: total number of epochs train_dataset_size: number of samples in the train dataset val_dataset_size: number of samples in the validation dataset batch_size: number of samples in a mini-batch loss_weights: array of weights for the loss term """ super().__init__() self.save_hyperparameters() self.learning_rate = learning_rate self.n_weight_samples = n_weight_samples self.kl_weighting_type = kl_weighting_type self.kl_weighting_scheme = kl_weighting_scheme self.max_epochs = max_epochs self.train_dataset_size = train_dataset_size self.val_dataset_size = val_dataset_size self.batch_size = batch_size self.IDs = torch.empty(0).type(torch.LongTensor) self.predicted_labels = torch.empty(0).type( torch.LongTensor).to('cuda') self.correct_predictions = torch.empty(0).type( torch.BoolTensor).to('cuda') self.epistemic_uncertainty = torch.empty(0).type( torch.FloatTensor).to('cuda') self.aleatoric_uncertainty = torch.empty(0).type( torch.FloatTensor).to('cuda') self.total_uncertainty = torch.empty(0).type( torch.FloatTensor).to('cuda') self.model = ECGResNet_VariationalInference( in_channels, n_grps, N, num_classes, dropout, first_width, stride, dilation, n_weight_samples, kl_weighting_type, kl_weighting_scheme) if loss_weights is not None: weights = torch.tensor(loss_weights, dtype=torch.float) else: weights = loss_weights self.loss = FocalLoss(gamma=1, weights=weights)
def __init__(self, in_channels, n_grps, N, num_classes, dropout, first_width, stride, dilation, learning_rate, ensemble_size, max_epochs, initial_lr, cyclical_learning_rate_type, loss_weights=None, **kwargs): """ Initializes the ECGResNetSnapshotEnsembleSystem Args: in_channels: number of channels of input n_grps: number of ResNet groups N: number of blocks per groups num_classes: number of classes of the classification problem dropout: probability of an argument to get zeroed in the dropout layer first_width: width of the first input stride: tuple with stride value per block per group dilation: spacing between the kernel points of the convolutional layers learning_rate: the learning rate of the model ensemble_size: the number of models that make up the ensemble max_epochs: total number of epochs to train for initial_lr: the initial learning rate at the start of a learning cycle cyclical_learning_rate_type: the type of learning rate cycling to apply loss_weights: array of weights for the loss term """ super().__init__() self.save_hyperparameters() self.learning_rate = learning_rate self.num_classes = num_classes self.ensemble_size = ensemble_size self.max_epochs = max_epochs self.initial_lr = initial_lr self.cyclical_learning_rate_type = cyclical_learning_rate_type self.IDs = torch.empty(0).type(torch.LongTensor) self.predicted_labels = torch.empty(0).type(torch.LongTensor) self.correct_predictions = torch.empty(0).type(torch.BoolTensor) self.epistemic_uncertainty = torch.empty(0).type(torch.FloatTensor) self.models = [] self.optimizers = [] # Initialize a single model during training self.models.append( ECGResNet(in_channels, n_grps, N, num_classes, dropout, first_width, stride, dilation)) if loss_weights is not None: weights = torch.tensor(loss_weights, dtype=torch.float) else: weights = loss_weights self.loss = FocalLoss(gamma=1, weights=weights) create_weights_directory()