Skip to content

Keras Training

Peter Fackeldey edited this page Feb 1, 2018 · 9 revisions

Training a neural network using Keras

Preparations...

Setup everything:

  • bash checkout_script.sh (only once)
  • bash setup.sh (for every new terminal)

Now you can start 🎉
One has to create his own specific <xxx>.yaml config file for an individual analysis (MANDATORY!). This should be added in the config/ directory. It specifies inputs, training variables, weights, paths, cuts and a lot more!!! The config file is the heart of all scripts and is required in the following steps.

First Step: Create a Trainingsset && Dump the Root Files to Numpy Arrays

In this step the root files have to pass a skimming step, where the input files are merged into one (easy to handle) root file for each fold. The cuts for each class are applied and a custom branch is appended to each tree containing all necessary plotting (event) weights. The folds are splitted by even and uneven event numbers. In the end you will get two trainingssets (fold 0 and fold 1) with your custom skimming. Working with standalone keras is only possible with numpy arrays. Now you have to dump the root files to numpy arrays for each fold! All of these steps are implemented in a luigi workflow. Just use:

python -m luigi --module run_luigi RootToNumpy --config-path config/<xxx>.yaml --local-scheduler

Second Step: 🔮 THE TRAINING 🔮

With the numpy arrays you can start a training (finally) for each fold separately. The hyperparameter can be set by using the argument parser of the script. More informations can be found with the --help or -h option.
If you want to run the training locally, do:

python training/train.py config/<xxx>.yaml

If you want to use the GPU machine for a training, make sure that you obtain an account. Then you need to log in to this machine and create a submission script similar to MSSM_HWW.submit. Finally you can put your job in the queue of the batch system via:

bsub<XXX.submit

More information on the GPU batch system of the RWTH Aachen can be found here

Third Step: Some Plotting... [WIP]

Plot metrics (loss, accuracy) vs epochs:

python plotting/deep_plots

For more detailed documentation and some exampled plots have a look at the corresponding ipython notebook (plotting/deep_plots.ipynb)!
Do confusion plots:

python plotting/confusionmatrix.py

For more detailed documentation and some exampled plots have a look at the corresponding ipython notebook (plotting/confusionmatrix.ipynb)!

Last Step: Evaluation/Application [WIP]

This is the last step. If you finally achieved a converging training you want to evaluate the trained neural network on new/unknown data. Here it is important to change the hierarchy of the folds:

  • Evaluate on fold 1 with training of fold 0
  • Evaluate on fold 0 with training of fold 1

This will allow you to use all the data in the end for both training and evaluating! The application is done by:

python evaluation/keras_evaluation.py config/<xxx>.yaml

It's done...
🎉 Congratulations!!! 🎉