deepSIP.training¶
-
class
deepSIP.training.
Train
(trainX, trainY, valX, valY, testX=None, testY=None, Ylim=[0.0, 1.0], seed=100, threshold=0.5, regression=True, mcnum=75, kernel=15, filters=16, fc_size=32, drop_rate=0.1, epochs=75, early_stop=[0.0], lr_decay_steps=[45, 60, 70], lr=0.001, batch_size=16, weight_decay=0.0001, verbose=True, wandb=None, save=True, savedir='./')¶ Bases:
object
network training
Parameters: - train[X,Y] : np.ndarray
training [inputs,outputs]
- val[X,Y] : np.ndarray
validation [inputs,outputs]
- test[X,Y] : np.ndarray, optional
testing [inputs,outputs]
- Ylim : tuple, list, or other iterable of length 2, optional
lower and upper limits for for utils.LinearScaler on outputs (Y)
- seed : int, optional
seed for random number generator
- threshold : float, optional
minimum threshold for ‘in’ classification by Domain model
- regression : bool, optional
toggle for regression (determines scalers used)
- mcnum : int, optional
number of stochastic forward passes to perform
- kernel : odd int, optional
convolutional kernel size
- filters : int, optional
number of filters in first convolution layer
- fc_size : int, optional
number of neurons in fully connected layer
- drop_rate : float, optional
dropout probability
- epochs : int, optional
number of training epochs
- lr : float, optional
initial learning rate
- batch_size : int, optional
batch size for training
- weight_decay : float, optional
weight decay for training
- verbose : bool, optional
show network summary and status bars
- save : bool, optional
flag for saving training history and trained model
- savedir : str, optional
directory for save files
Other Parameters: - early_stop : length-1 array_like, optional
early stopping threshold on validation RMSE for regression mode
- lr_decay_steps : array_like, optional
epochs at which to decay learning rate by factor 10
- wandb : wandb instance, optional
wandb instance for run tracking
Attributes: - device : torch.device
device type being used (GPU if available, else CPU)
- network : DropoutCNN
network to train (may be wrapped in DataParallel if on GPU)
- Yscaler : VoidScaler or LinearScaler
scaler for Y labels
- optimizer : torch optimizer (Adam)
optimizer for training
- scheduler : VoidLRScheduler or MultiStepLR
learning rate scheduler
- loss : torch loss
loss for training
Methods
test_epoch
(self, X, Y[, label])perform validation or testing steps for single epoch train
(self)train network train_epoch
(self)perform training steps for single epoch -
train_epoch
(self)¶ perform training steps for single epoch
Returns: - dict
training metrics for epoch (loss and lr-current)
-
test_epoch
(self, X, Y, label='')¶ perform validation or testing steps for single epoch
Parameters: - X : torch.tensor
inputs
- Y : torch.tensor
outputs
- label : str, optional
label to prepend output dict keys with (e.g. ‘val’ or ‘test’)
Returns: - metrics : dict
validation or testing metrics for epoch
-
train
(self)¶ train network
-
class
deepSIP.training.
Sweep
(trainX, trainY, valX, valY, entity, project, kernels, filters, fc_sizes, drop_rates, batch_sizes, lrs, weight_decays, seed=100, regression=True, mcnum=75, epochs=75, early_stop=[0.0], Ylim=[0.0, 1.0], sweep_method='random', testX=None, testY=None)¶ Bases:
object
sweep (search) through hyperparameters using wandb
Parameters: - train[X,Y] : np.ndarray
training [inputs,outputs]
- val[X,Y] : np.ndarray
validation [inputs,outputs]
- entity : str
wandb entity
- project : str
wandb project
- kernels : array_like
convolutional kernel sizes to sweep over
- filters : array_like
numbers of filters in first convolution layer to sweep over
- fc_sizes : array_like
numbers of neurons in fully connected layer to sweep over
- drop_rates : array_like
dropout probabilities to sweep over
- batch_sizes : array_like
batch sizes to sweep over
- lrs : array_like
initial learning rates to sweep over
- weight_decays : array_like
weight decays to sweep over
- seed : int, optional
seed for random number generator
- regression : bool, optional
toggle for regression (determines scalers used)
- mcnum : int, optional
number of stochastic forward passes to perform
- epochs : int, optional
number of training epochs
- Ylim : tuple, list, or other iterable of length 2, optional
lower and upper limits for for utils.LinearScaler on outputs (Y)
- sweep_method : str, optional
method for sweep (‘random’ or ‘grid’)
- test[X,Y] : np.ndarray, optional
testing [inputs,outputs]
Other Parameters: - early_stop : length-1 array_like, optional
early stopping threshold on validation RMSE for regression mode
Attributes: - sweep_config : dict
wandb sweep configurations
Methods
sweep
(self[, tags, saveroot])run sweep -
sweep
(self, tags=[], saveroot=None)¶ run sweep
Parameters: - tags : list, optional
list of strings to add as tags to sweep runs
- saveroot : str, optional
root name to use for saving