Trainer#
- class Trainer(args, model=None, optimizer=None)#
Bases:
object
This class represents a training object, that has all the needed components for a training, like dataLoaders, optimizer, model etc.
- __init__(args, model=None, optimizer=None)#
Initializes the model, optimizer and data generators, based on user defined arguments. In case model and optimizer are passed - they are used, In case any of those arguments is None, the values are initialized from scratch, based on user arguments
- Parameters:
args (Arguments) – user defined arguments
model (nn.Model) – Either a partually trained model (loaded from check point) or None. In case no model is passed, the model is loaded based on user arguments, by name
optimizer (Optimizer) – The optimizer to use during training (loaded from check point) or None. In case no model is passed, the optimizer is loaded based on user arguments
Methods
__init__
(args[, model, optimizer])Initializes the model, optimizer and data generators, based on user defined arguments.
Runs the model on the given data.
get_all_ranges
(args)lists all activations ranges (min and max) in a single list
Returns the model to be trained
Returns the optimizer of the training
get_range_aware_act
(args)test
(args, epoch)tests the model on the given data
train_step
(args, epoch, t)performs a single train step (a single forward and backward pass)
validation
(args, epoch)tests the model on the given data
- approximate_input_range_from_data(args)#
Runs the model on the given data. As the result, each range aware activation in the model (if any) will hold the correct actual data range - minimum and maximum values of all inputs it recieved during the approximation run on the approximation data set. This ranges are used when approximation the range aware relu by range aware polynomial, as polynomial approximation requires a range
- Parameters:
args (Arguments) – user arguments
- get_all_ranges(args)#
lists all activations ranges (min and max) in a single list
- Parameters:
args (Arguments) – user arguments
- Returns:
ranges (two numbers for each activation, that represent minimum and maximum of the activation range)
- Return type:
list<float>
- get_model()#
Returns the model to be trained
- Returns:
the model to be trained
- Return type:
nn.model
- get_optimizer()#
Returns the optimizer of the training
- Returns:
the optimizer of the training
- Return type:
optimizer
- test(args, epoch: int)#
tests the model on the given data
- Parameters:
args (Arguments) – user arguments
epoch (int) – epoch number
- Raises:
Exception – Exit because of NaNs, if Nan values are present in the output, and args.continue_with_nans=False
- Returns:
metrics np.array: confusion matrix
- Return type:
MetricsTracker
- train_step(args, epoch: int, t: tqdm)#
performs a single train step (a single forward and backward pass)
- Parameters:
args (Arguments) – user arguments
epoch (int) – the current epoch number (for epoch summary printing)
t (tqdm) – training progress (the progress is updated after each epoch)
- Raises:
Exception – Exit because of NaNs, if Nan values are present in the output, and args.continue_with_nans=False
- Returns:
metrics np.array: confusion matrix
- Return type:
MetricsTracker
- validation(args, epoch: int)#
tests the model on the given data
- Parameters:
args (Arguments) – user arguments
epoch (int) – epoch number
- Raises:
Exception – Exit because of NaNs, if Nan values are present in the output, and args.continue_with_nans=False
- Returns:
metrics np.array: confusion matrix
- Return type:
MetricsTracker