template.runner.multi_label_image_classification package¶
Submodules¶
template.runner.multi_label_image_classification.evaluate module¶
-
template.runner.multi_label_image_classification.evaluate.
get_preds_from_minibatch
(minibatch)[source]¶
-
template.runner.multi_label_image_classification.evaluate.
jaccard_similarity_score
(targets, preds)[source]¶
template.runner.multi_label_image_classification.multi_label_image_classification module¶
This file is the template for the boilerplate of train/test of a DNN for image classification
There are a lot of parameter which can be specified to modify the behaviour and they should be used instead of hard-coding stuff.
-
class
template.runner.multi_label_image_classification.multi_label_image_classification.
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
template.runner.multi_label_image_classification.setup module¶
-
template.runner.multi_label_image_classification.setup.
set_up_dataloaders
(model_expected_input_size, dataset_folder, batch_size, workers, disable_dataset_integrity, enable_deep_dataset_integrity, inmem=False, **kwargs)[source]¶ Set up the dataloaders for the specified datasets.
- Parameters
model_expected_input_size (tuple) – Specify the height and width that the model expects.
dataset_folder (string) – Path string that points to the three folder train/val/test. Example: ~/../../data/svhn
batch_size (int) – Number of datapoints to process at once
workers (int) – Number of workers to use for the dataloaders
inmem (boolean) – Flag: if False, the dataset is loaded in an online fashion i.e. only file names are stored and images are loaded on demand. This is slower than storing everything in memory.
- Returns
train_loader (torch.utils.data.DataLoader)
val_loader (torch.utils.data.DataLoader)
test_loader (torch.utils.data.DataLoader) – Dataloaders for train, val and test.
int – Number of classes for the model.
template.runner.multi_label_image_classification.train module¶
-
template.runner.multi_label_image_classification.train.
jaccard_similarity_score
(targets, preds)[source]¶
-
template.runner.multi_label_image_classification.train.
train
(train_loader, model, criterion, optimizer, writer, epoch, no_cuda=False, log_interval=25, **kwargs)[source]¶ Training routine
- Parameters
train_loader (torch.utils.data.DataLoader) – The dataloader of the train set.
model (torch.nn.module) – The network model being used.
criterion (torch.nn.loss) – The loss function used to compute the loss of the model.
optimizer (torch.optim) – The optimizer used to perform the weight update.
writer (tensorboardX.writer.SummaryWriter) – The tensorboard writer object. Used to log values on file for the tensorboard visualization.
epoch (int) – Number of the epoch (for logging purposes).
no_cuda (boolean) – Specifies whether the GPU should be used or not. A value of ‘True’ means the CPU will be used.
log_interval (int) – Interval limiting the logging of mini-batches. Default value of 10.
- Returns
top1.avg – Accuracy of the model of the evaluated split
- Return type
-
template.runner.multi_label_image_classification.train.
train_one_mini_batch
(model, criterion, optimizer, input, target, loss_meter, jss_meter)[source]¶ This routing train the model passed as parameter for one mini-batch
- Parameters
model (torch.nn.module) – The network model being used.
criterion (torch.nn.loss) – The loss function used to compute the loss of the model.
optimizer (torch.optim) – The optimizer used to perform the weight update.
input (torch.autograd.Variable) – The input data for the mini-batch
target (torch.autograd.Variable) – The target data (labels) for the mini-batch
loss_meter (AverageMeter) – Tracker for the overall loss
jss_meter (AverageMeter) – Tracker for the overall Jaccard Similarity Score
- Returns
loss – Loss for this mini-batch
- Return type
Module contents¶
-
class
template.runner.multi_label_image_classification.
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