template.runner package¶
Subpackages¶
- template.runner.apply_model package
- template.runner.bidimensional package
- template.runner.image_classification package
- template.runner.multi_label_image_classification package
- Submodules
- template.runner.multi_label_image_classification.evaluate module
- template.runner.multi_label_image_classification.multi_label_image_classification module
- template.runner.multi_label_image_classification.setup module
- template.runner.multi_label_image_classification.train module
- Module contents
- template.runner.process_activation package
- template.runner.triplet package
Module contents¶
-
class
template.runner.
ApplyModel
[source]¶ Bases:
object
-
static
single_run
(writer, current_log_folder, model_name, lr, output_channels, classify, **kwargs)[source]¶ This is the main routine where train(), validate() and test() are called.
- Parameters
writer (Tensorboard SummaryWriter) – Responsible for writing logs in Tensorboard compatible format.
current_log_folder (string) – Path to where logs/checkpoints are saved
model_name (string) – Name of the model
lr (float) – Value for learning rate
kwargs (dict) – Any additional arguments.
output_channels (int) – Specify shape of final layer of network.
classify (boolean) – Specifies whether to generate a classification report for the data or not.
- Returns
None – None
- Return type
-
static
-
class
template.runner.
Bidimensional
[source]¶ Bases:
template.runner.image_classification.image_classification.ImageClassification
-
static
single_run
(writer, current_log_folder, model_name, epochs, lr, decay_lr, validation_interval, checkpoint_all_epochs, **kwargs)[source]¶ This is the main routine where train(), validate() and test() are called.
- Parameters
writer (Tensorboard.SummaryWriter) – Responsible for writing logs in Tensorboard compatible format.
current_log_folder (string) – Path to where logs/checkpoints are saved
model_name (string) – Name of the model
epochs (int) – Number of epochs to train
lr (float) – Value for learning rate
kwargs (dict) – Any additional arguments.
decay_lr (boolean) – Decay the lr flag
validation_interval (int) – Run evaluation on validation set every N epochs
checkpoint_all_epochs (bool) – If enabled, save checkpoint after every epoch.
- Returns
train_value (ndarray[floats] of size (1, epochs)) – Accuracy values for train split
val_value (ndarray[floats] of size (1, `epochs`+1)) – Accuracy values for validation split
test_value (float) – Accuracy value for test split
-
static
-
class
template.runner.
DivahisdbSemanticSegmentation
[source]¶ Bases:
template.runner.image_classification.image_classification.ImageClassification
-
class_encoding
= None¶
-
img_names_sizes_dict
= None¶
-
-
class
template.runner.
ImageClassification
[source]¶ Bases:
object
-
classmethod
prepare
(model_name, **kwargs)[source]¶ Loads and prepares the data, the optimizer and the criterion
- Parameters
model_name (str) – Name of the model. Used for loading the model.
kwargs (dict) – Any additional arguments.
- Returns
model (DataParallel) – The model to train
num_classes (int) – How many different classes there are in our problem. Used for loading the model.
best_value (float) – Best value of the model so far. Non-zero only in case of –resume being used
train_loader (torch.utils.data.dataloader.DataLoader) – Training dataloader
val_loader (torch.utils.data.dataloader.DataLoader) – Validation dataloader
test_loader (torch.utils.data.dataloader.DataLoader) – Test set dataloader
optimizer (torch.optim) – Optimizer to use during training, e.g. SGD
criterion (torch.nn.modules.loss) – Loss function to use, e.g. cross-entropy
-
classmethod
single_run
(**kwargs)[source]¶ This is the main routine where train(), validate() and test() are called.
- Returns
train_value (ndarray[floats] of size (1, epochs)) – Accuracy values for train split
val_value (ndarray[floats] of size (1, `epochs`+1)) – Accuracy values for validation split
test_value (float) – Accuracy value for test split
-
classmethod
test_routine
(model_name, num_classes, criterion, epochs, current_log_folder, writer, **kwargs)[source]¶ Load the best model according to the validation score (early stopping) and runs the test routine.
- Parameters
model_name (str) – name of the model. Used for loading the model.
num_classes (int) – How many different classes there are in our problem. Used for loading the model.
criterion (torch.nn.modules.loss) – Loss function to use, e.g. cross-entropy
epochs (int) – After how many epochs are we testing
current_log_folder (string) – Path to where logs/checkpoints are saved
writer (Tensorboard.SummaryWriter) – Responsible for writing logs in Tensorboard compatible format.
kwargs (dict) – Any additional arguments.
- Returns
test_value – Accuracy value for test split
- Return type
-
classmethod
train_routine
(best_value, decay_lr, validation_interval, start_epoch, epochs, checkpoint_all_epochs, current_log_folder, **kwargs)[source]¶ Performs the training and validatation routines
- Parameters
best_value (float) – Best value of the model so far. Non-zero only in case of –resume being used
decay_lr (boolean) – Decay the lr flag
validation_interval (int) – Run evaluation on validation set every N epochs
start_epoch (int) – Int to initialize the starting epoch. Non-zero only in case of –resume being used
epochs (int) – Number of epochs to train
checkpoint_all_epochs (bool) – Save checkpoint at each epoch
current_log_folder (string) – Path to where logs/checkpoints are saved
kwargs (dict) – Any additional arguments.
- Returns
train_value (ndarray[floats] of size (1, epochs)) – Accuracy values for train split
val_value (ndarray[floats] of size (1, `epochs`+1)) – Accuracy values for validation split
-
classmethod
-
class
template.runner.
MultiLabelImageClassification
[source]¶ Bases:
object
-
static
single_run
(writer, current_log_folder, model_name, epochs, lr, decay_lr, validation_interval, checkpoint_all_epochs, **kwargs)[source]¶ This is the main routine where train(), validate() and test() are called.
- Parameters
writer (Tensorboard.SummaryWriter) – Responsible for writing logs in Tensorboard compatible format.
current_log_folder (string) – Path to where logs/checkpoints are saved
model_name (string) – Name of the model
epochs (int) – Number of epochs to train
lr (float) – Value for learning rate
kwargs (dict) – Any additional arguments.
decay_lr (boolean) – Decay the lr flag
validation_interval (int) – Run evaluation on validation set every N epochs
checkpoint_all_epochs (bool) – If enabled, save checkpoint after every epoch.
- Returns
train_value (ndarray[floats] of size (1, epochs)) – Accuracy values for train split
val_value (ndarray[floats] of size (1, `epochs`+1)) – Accuracy values for validation split
test_value (float) – Accuracy value for test split
-
static
-
class
template.runner.
SemanticSegmentation
[source]¶ Bases:
template.runner.image_classification.image_classification.ImageClassification
-
class_encoding
= None¶
-
img_names_sizes_dict
= None¶
-
-
class
template.runner.
Triplet
[source]¶ Bases:
object
-
static
single_run
(writer, current_log_folder, model_name, epochs, lr, decay_lr, margin, anchor_swap, validation_interval, regenerate_every, checkpoint_all_epochs, only_evaluate, **kwargs)[source]¶ This is the main routine where train(), validate() and test() are called.
- Parameters
writer (Tensorboard SummaryWriter) – Responsible for writing logs in Tensorboard compatible format.
current_log_folder (string) – Path to where logs/checkpoints are saved
model_name (string) – Name of the model
epochs (int) – Number of epochs to train
lr (float) – Value for learning rate
margin (float) – The margin value for the triplet loss function
anchor_swap (boolean) – Turns on anchor swap
decay_lr (boolean) – Decay the lr flag
validation_interval (int) – Run evaluation on validation set every N epochs
regenerate_every (int) – Re-generate triplets every N epochs
checkpoint_all_epochs (bool) – If enabled, save checkpoint after every epoch.
only_evaluate (boolean) – Flag : if True, only the test set is loaded.
- Returns
Mean Average Precision values for train and validation splits.
- Return type
train_value, val_value, test_value
-
static