-
Notifications
You must be signed in to change notification settings - Fork 1
Keras Training
Peter Fackeldey edited this page Oct 26, 2017
·
9 revisions
In order to perform a training you can use the general train.py
script or write your own specific one. The script is designed to be called with a config (.yaml) file, which specifies mainly all training files, weights and training features.
The first step is to load the TMVA tools:
import ROOT
ROOT.TMVA.Tools.Instance()
ROOT.TMVA.PyMethodBase.PyInitialize()
Then one can initialize an instance of the TMVA::Factory():
factory = ROOT.TMVA.Factory("TMVAclassification", ROOT.TFile.Open("training_output.root", "RECREATE"),
"!V:!Silent:Color:!DrawProgressBar:Transformations=None:AnalysisType=Classification")
Now the signal TTrees, the background TTrees and the training features can be added to the factory. Then the neural network method has to be booked:
model = KerasModels(n_features=len(config["features"]), n_classes=len(
config["classes"]), learning_rate=0.0005)
model.example_model()
factory.BookMethod(dataloader, ROOT.TMVA.Types.kPyKeras, "PyKeras_example", "!H:!V:VarTransform=None:FileNameModel=example_model.h5:SaveBestOnly=true:TriesEarlyStopping=-1:NumEpochs={}:".format(EPOCHS) + "BatchSize={}".format(BATCH_SIZE))
Finally your methods can be trained, tested and evaluated!!!