Refactor learning_state_initialization
The learning_state_initialization
function in train_pytorch_model.py#L46-L198 takes a lot of input arguments (26) and returns a tuple with a lot of elements (19) which makes it difficult to read and error prone when unpacking return value.
I list here some easy improvements:
-
remove duplicate output dataset_sensor_pos
-
group the output validation metrics ( loss
,kappa
,fscore
,oa
) in a structure (ex: dataclass) -
group the input early stop parameters ( patience
,tol
,metric
) in a structure and removeenable_early_stop
-
move input model parameters ( nb_features
,nb_class
) in thedl_parameters
dictionary -
group input hyperparameters ( learning_rate
,batch_size
,epochs
) in a structure -
group output train/valid couples ( train/valid_loader
,train/valid_loss
,batch_prov_train/valid
) in tuples
With only these minor changes the function can go:
- from 26 inputs / 19 outputs
- to 20 inputs / 12 outputs
This can be improved further with object-oriented tricks, but this pure functional style refactoring has already a good effort to outcome ratio.