Train¶
The network can be trained using three interfaces:
python, via
das.train.trainthe command-line interface
das train.the GUI - see the GUI tutorial
Training will:
load train/val/test data form a dataset
initialize the network
save all parameters for reproducibility
train the network and save the best network to disk
run inference and evaluate the network using the test data.
The names of files created during training start with an optional prefix and the time stamp of the start time of training, as in my-awesome-prefix_20192310_091032. Typically, three files are created:
*_params.yaml- training parameters etc.*_model.h5- model architecture and weights*_results.h5- predictions and evaluation results for the test set (only created if the training dataset contains a test set)
Training using python¶
Training is done using the train function in the das.train module:
import das.train
help(das.train.train)
Calling the train function produce fairly verbose logging messages, to help with troubleshooting:
run time parameters
information on the size of the training and validation data
network architecture
training progress (training and validation loss)
after training, a classification report for the test data (if test data exist in the dataset)
When done, train returns the trained keras model and a parameter dictionary with all arguments required to reproduce the model.
To demonstrate the outputs of train, the following trains a small network on a small dataset to annotate pulse and sine song from Drosophila melanogater. Expected performance (f1-score) is about 75%.
model, params = das.train.train(model_name='tcn', # see `das.models` for valid model_names
data_dir='tutorial_dataset.npy',
save_dir='res',
nb_hist=256,
kernel_size=16,
nb_filters=16,
ignore_boundaries=True,
verbose=1,
nb_epoch=4,
log_messages=True)
Training using command-line scripts¶
The training function das.train.train and all its arguments are also accessible from the command line via das train for use on the terminal. See here for a description of all command-line arguments. The command-line interface is generated with defopt.
For instance, training command above can be invoked from the command line:
das train --data-dir dat/dmel_single_raw.npy --save-dir res --model-name tcn --kernel-size 16 --nb-filters 16 --nb-hist 512 --nb-epoch 20 -i
Shell scripts are particularly useful if you want to fit the network with with different configurations to optimize structural parameters. For instance, this script will fit networks with different numbers of TCN blocks (nb_conv) and filters (nb_filters):
#!/bin/bash
conda activate das
YSUFFIX="pulse"
MODELNAME='tcn'
DATADIR='../dat/dmel_single.npy'
SAVEDIR="res"
NB_HIST=2048
KERNEL_SIZE=32
NB_FILTERS=32
NB_CONV=3
for NB_CONV in 2 3 4
do
for NB_FILTERS in 16 32 64
do
das train -i --nb-filters $NB_FILTERS --kernel-size $KERNEL_SIZE --nb-conv $NB_CONV --nb-hist $NB_HIST --save-dir $SAVEDIR --y-suffix $YSUFFIX --data-dir $DATADIR --model-name $MODELNAME
done
done
A description of all command line arguments can be obtained by typing das train --help in a terminal:
!das train --help