36useTMVACNN = opt[0]
if len(opt) > 0
else False
37useKerasCNN = opt[1]
if len(opt) > 1
else useKerasCNN
38useTMVADNN = opt[2]
if len(opt) > 2
else False
39useTMVABDT = opt[3]
if len(opt) > 3
else False
40usePyTorchCNN = opt[4]
if len(opt) > 4
else False
51 print(
"TMVA_CNN_Classificaton",
"Skip using PyTorch since torch is not installed")
67 fileOutName =
"images_data_16x16.root"
74 sX2 = sX1 + delta_sigma
75 sY2 = sY1 - delta_sigma
76 h1 =
ROOT.TH2D(
"h1",
"h1", nh, 0, 10, nw, 0, 10)
77 h2 =
ROOT.TH2D(
"h2",
"h2", nh, 0, 10, nw, 0, 10)
81 bkg =
ROOT.TTree(
"bkg_tree",
"background_tree")
83 f =
TFile(fileOutName,
"RECREATE")
98 ROOT.Info(
"TMVA_CNN_Classification",
"Filling ROOT tree \n")
101 print(
"Generating image event ...", i)
127 print(
"Signal and background tree with images data written to the file %s",
f.GetName())
137if (
not hasCPU
and not hasGPU) :
138 ROOT.Warning(
"TMVA_CNN_Classificaton",
"ROOT is not supporting tmva-cpu and tmva-gpu skip using TMVA-DNN and TMVA-CNN")
144 usePyTorchCNN =
False
150 "TMVA_CNN_Classificaton",
151 "TMVA is not build with GPU or CPU multi-thread support. Cannot use TMVA Deep Learning for CNN",
154writeOutputFile =
True
166 print(
"Running in serial mode since ROOT does not support MT")
173 outputFile =
TFile.Open(
"TMVA_CNN_ClassificationOutput.root",
"RECREATE")
198 "TMVA_CNN_Classification",
204 AnalysisType=
"Classification",
205 Transformations=
None,
228inputFileName =
"images_data_16x16.root"
252backgroundWeight = 1.0
278nTrainSig = 0.8 * nEventsSig
279nTrainBkg = 0.8 * nEventsBkg
286 nTrain_Signal=nTrainSig,
287 nTrain_Background=nTrainBkg,
290 NormMode=
"NumEvents",
292 CalcCorrelations=
False,
318 BoostType=
"AdaBoost",
321 BaggedSampleFraction=0.5,
322 SeparationType=
"GiniIndex",
334 "DENSE|100|RELU,BNORM,DENSE|100|RELU,BNORM,DENSE|100|RELU,BNORM,DENSE|100|RELU,DENSE|1|LINEAR"
341 "LearningRate=1e-3,Momentum=0.9,Repetitions=1,"
342 "ConvergenceSteps=5,BatchSize=100,TestRepetitions=1,"
343 "WeightDecay=1e-4,Regularization=None,"
344 "Optimizer=ADAM,DropConfig=0.0+0.0+0.0+0."
346 trainingString1 +=
",MaxEpochs=" + str(max_epochs)
349 dnnMethodName =
"TMVA_DNN_CPU"
355 dnnMethodName =
"TMVA_DNN_GPU"
363 ErrorStrategy=
"CROSSENTROPY",
365 WeightInitialization=
"XAVIER",
367 TrainingStrategy=trainingString1,
368 Architecture=dnnOptions
402 "LearningRate=1e-3,Momentum=0.9,Repetitions=1,"
403 "ConvergenceSteps=5,BatchSize=100,TestRepetitions=1,"
404 "WeightDecay=1e-4,Regularization=None,"
405 "Optimizer=ADAM,DropConfig=0.0+0.0+0.0+0.0"
407 trainingString1 +=
",MaxEpochs=" + str(max_epochs)
410 cnnMethodName =
"TMVA_CNN_CPU"
415 cnnMethodName =
"TMVA_CNN_GPU"
423 ErrorStrategy=
"CROSSENTROPY",
425 WeightInitialization=
"XAVIER",
426 InputLayout=
"1|16|16",
427 Layout=
"CONV|10|3|3|1|1|1|1|RELU,BNORM,CONV|10|3|3|1|1|1|1|RELU,MAXPOOL|2|2|1|1,RESHAPE|FLAT,DENSE|100|RELU,DENSE|1|LINEAR",
428 TrainingStrategy=trainingString1,
429 Architecture=cnnOptions,
437 ROOT.Info(
"TMVA_CNN_Classification",
"Using Convolutional PyTorch Model")
439 pyTorchFileName +=
"/tmva/PyTorch_Generate_CNN_Model.py"
446 ROOT.Info(
"TMVA_CNN_Classification",
"Booking PyTorch CNN model")
454 FilenameModel=
"PyTorchModelCNN.pt",
455 FilenameTrainedModel=
"PyTorchTrainedModelCNN.pt",
456 NumEpochs=max_epochs,
458 UserCode=str(pyTorchFileName)
462 "TMVA_CNN_Classification",
463 "PyTorch is not installed or model building file is not existing - skip using PyTorch",
467 ROOT.Info(
"TMVA_CNN_Classification",
"Building convolutional keras model")
480 model.add(Reshape((16, 16, 1), input_shape=(256,)))
481 model.add(
Conv2D(10, kernel_size=(3, 3), kernel_initializer=
"TruncatedNormal", activation=
"relu", padding=
"same"))
482 model.add(
Conv2D(10, kernel_size=(3, 3), kernel_initializer=
"TruncatedNormal", activation=
"relu", padding=
"same"))
489 model.compile(loss=
"binary_crossentropy", optimizer=
Adam(learning_rate=0.001), weighted_metrics=[
"accuracy"])
497 ROOT.Info(
"TMVA_CNN_Classification",
"Booking convolutional keras model")
505 FilenameModel=
"model_cnn.h5",
506 FilenameTrainedModel=
"trained_model_cnn.h5",
507 NumEpochs=max_epochs,
509 GpuOptions=
"allow_growth=True",
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t format
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
This is the main MVA steering class.