bob.ip.binseg.engine.trainer

Functions

check_exist_logfile(logfile_name, arguments)

Check existance of logfile (trainlog.csv), If the logfile exist the and the epochs number are still 0, The logfile will be replaced.

check_gpu(device)

Check the device type and the availability of GPU.

checkpointer_process(checkpointer, ...)

Process the checkpointer, save the final model and keep track of the best model.

create_logfile_fields(valid_loader, device)

Creation of the logfile fields that will appear in the logfile.

run(model, data_loader, valid_loader, ...)

Fits an FCN model using supervised learning and save it to disk.

save_model_summary(output_folder, model)

Save a little summary of the model in a txt file.

static_information_to_csv(...)

Save the static information in a csv file.

torch_evaluation(model)

Context manager to turn ON/OFF model evaluation

train_sample_process(samples, model, ...)

Processing the training inputs (Images, ground truth, masks) and apply the backprogration to update the training losses.

valid_sample_process(samples, model, ...)

Processing the validation inputs (Images, ground truth, masks) and update validation losses.

write_log_info(epoch, current_time, ...)

Write log info in trainlog.csv

bob.ip.binseg.engine.trainer.torch_evaluation(model)[source]

Context manager to turn ON/OFF model evaluation

This context manager will turn evaluation mode ON on entry and turn it OFF when exiting the with statement block.

Parameters

model (torch.nn.Module) – Network (e.g. driu, hed, unet)

Yields

model (torch.nn.Module) – Network (e.g. driu, hed, unet)

bob.ip.binseg.engine.trainer.check_gpu(device)[source]

Check the device type and the availability of GPU.

Parameters

device (torch.device) – device to use

bob.ip.binseg.engine.trainer.save_model_summary(output_folder, model)[source]

Save a little summary of the model in a txt file.

Parameters
  • output_folder (str) – output path

  • model (torch.nn.Module) – Network (e.g. driu, hed, unet)

Returns

  • r (str) – The model summary in a text format.

  • n (int) – The number of parameters of the model.

bob.ip.binseg.engine.trainer.static_information_to_csv(static_logfile_name, device, n)[source]

Save the static information in a csv file.

Parameters

static_logfile_name (str) – The static file name which is a join between the output folder and “constant.csv”

bob.ip.binseg.engine.trainer.check_exist_logfile(logfile_name, arguments)[source]

Check existance of logfile (trainlog.csv), If the logfile exist the and the epochs number are still 0, The logfile will be replaced.

Parameters
  • logfile_name (str) – The logfile_name which is a join between the output_folder and trainlog.csv

  • arguments (dict) – start and end epochs

bob.ip.binseg.engine.trainer.create_logfile_fields(valid_loader, device)[source]

Creation of the logfile fields that will appear in the logfile.

Parameters
  • valid_loader (torch.utils.data.DataLoader) – To be used to validate the model and enable automatic checkpointing. If set to None, then do not validate it.

  • device (torch.device) – device to use

Returns

logfile_fields – The fields that will appear in trainlog.csv

Return type

tuple

bob.ip.binseg.engine.trainer.train_sample_process(samples, model, optimizer, losses, device, criterion)[source]

Processing the training inputs (Images, ground truth, masks) and apply the backprogration to update the training losses.

Parameters
Returns

bob.ip.binseg.engine.trainer.valid_sample_process(samples, model, valid_losses, device, criterion)[source]

Processing the validation inputs (Images, ground truth, masks) and update validation losses.

Parameters
Returns

valid_losses

Return type

bob.ip.binseg.utils.measure.SmoothedValue

bob.ip.binseg.engine.trainer.checkpointer_process(checkpointer, checkpoint_period, valid_losses, lowest_validation_loss, arguments, epoch, max_epoch)[source]

Process the checkpointer, save the final model and keep track of the best model.

Parameters
bob.ip.binseg.engine.trainer.write_log_info(epoch, current_time, eta_seconds, losses, valid_losses, optimizer, logwriter, logfile, device)[source]

Write log info in trainlog.csv

Parameters
bob.ip.binseg.engine.trainer.run(model, data_loader, valid_loader, optimizer, criterion, scheduler, checkpointer, checkpoint_period, device, arguments, output_folder)[source]

Fits an FCN model using supervised learning and save it to disk.

This method supports periodic checkpointing and the output of a CSV-formatted log with the evolution of some figures during training.

Parameters