diff --git a/Train/DeepJetTrain_PF.py b/Train/DeepJetTrain_PF.py index 3ea8eed..e7e0533 100644 --- a/Train/DeepJetTrain_PF.py +++ b/Train/DeepJetTrain_PF.py @@ -60,13 +60,13 @@ startlearnrate=0.0005 from DeepJet_callbacks import DeepJet_callbacks -callbacks=DeepJet_callbacks(stop_patience=100, +callbacks=DeepJet_callbacks(stop_patience=300, lr_factor=0.5, lr_patience=3, lr_epsilon=0.003, lr_cooldown=6, - lr_minimum=0.00001, + lr_minimum=0.000001, outputDir=outputDir) useweights=False @@ -76,8 +76,6 @@ from DataCollection import DataCollection -from TrainData_deepCSV_ST import TrainData_deepCSV_ST -from TrainData_deepCSV import TrainData_deepCSV traind=DataCollection() traind.readFromFile(inputData) @@ -118,7 +116,7 @@ print(traind.getTruthShape()[0]) from DeepJet_models import Dense_model_broad, Dense_model_broad_flat #model = Dense_model_Rec(inputs,traind.getTruthShape()[0],shapes,0.3) -model = Dense_model_broad_flat(inputs,traind.getTruthShape()[0],shapes,0.1) +model = Dense_model_broad(inputs,traind.getTruthShape()[0],shapes,0.1) #model = Dense_model_broad(inputs,traind.getTruthShape()[0],shapes,0.1) print('compiling') diff --git a/convertFromRoot/convertFromRoot.py b/convertFromRoot/convertFromRoot.py index 089048c..6cc1613 100755 --- a/convertFromRoot/convertFromRoot.py +++ b/convertFromRoot/convertFromRoot.py @@ -73,6 +73,7 @@ def main(argv=None): from TrainData import TrainData from TrainData_deepCSV import TrainData_deepCSV + from TrainData_deepConvCSV import TrainData_deepConvCSV from TrainData_deepCMVA import TrainData_deepCMVA from TrainData_deepCSV_PF import TrainData_deepCSV_PF,TrainData_deepCSV_miniPF,TrainData_deepCSV_microPF from TrainData_deepConvCSV import TrainData_deepConvCSV @@ -83,6 +84,8 @@ def main(argv=None): traind=TrainData if Class == 'TrainData_deepCSV': traind=TrainData_deepCSV + elif Class == 'TrainData_deepConvCSV': + traind=TrainData_deepConvCSV elif Class == 'TrainData_deepJet_Reg': traind=TrainData_deepJet_Reg elif Class == 'TrainData_deepCSV_PF': diff --git a/modules/DataCollection.py b/modules/DataCollection.py index 319966d..01ec9ae 100644 --- a/modules/DataCollection.py +++ b/modules/DataCollection.py @@ -5,6 +5,8 @@ ''' #from tensorflow.contrib.labeled_tensor import batch #from builtins import list +from __future__ import print_function + from Weighter import Weighter from TrainData import TrainData, fileTimeOut #for convenience diff --git a/modules/DeepJet_callbacks.py b/modules/DeepJet_callbacks.py index 0cc5404..8278624 100644 --- a/modules/DeepJet_callbacks.py +++ b/modules/DeepJet_callbacks.py @@ -3,6 +3,7 @@ @author: jkiesele ''' +from __future__ import print_function from ReduceLROnPlateau import ReduceLROnPlateau from keras.callbacks import Callback, EarlyStopping,History,ModelCheckpoint #, ReduceLROnPlateau # , TensorBoard diff --git a/modules/DeepJet_models.py b/modules/DeepJet_models.py index 7816891..58b7f3b 100644 --- a/modules/DeepJet_models.py +++ b/modules/DeepJet_models.py @@ -164,15 +164,11 @@ def Dense_model_broad(Inputs,nclasses,Inputshapes,dropoutRate=-1): cpf = Convolution1D(64, 1, kernel_initializer='lecun_uniform', activation='relu')(Inputs[1]) cpf = Dropout(dropoutRate)(cpf) - cpf = Convolution1D(64, 1, kernel_initializer='lecun_uniform', activation='relu')(cpf) - cpf = Dropout(dropoutRate)(cpf) - cpf = Convolution1D(32, 1, kernel_initializer='lecun_uniform', activation='relu')(cpf) - cpf = Dropout(dropoutRate)(cpf) cpf = Convolution1D(32, 1, kernel_initializer='lecun_uniform', activation='relu')(cpf) cpf = Dropout(dropoutRate)(cpf) cpf = Convolution1D(32, 1, kernel_initializer='lecun_uniform', activation='relu')(cpf) cpf = Dropout(dropoutRate)(cpf) - cpf = Convolution1D(16, 1, kernel_initializer='lecun_uniform', activation='relu')(cpf) + cpf = Convolution1D(8, 1, kernel_initializer='lecun_uniform', activation='relu')(cpf) cpf = Flatten()(cpf) @@ -180,31 +176,23 @@ def Dense_model_broad(Inputs,nclasses,Inputshapes,dropoutRate=-1): npf = Dropout(dropoutRate)(npf) npf = Convolution1D(16, 1, kernel_initializer='lecun_uniform', activation='relu')(npf) npf = Dropout(dropoutRate)(npf) - npf = Convolution1D(16, 1, kernel_initializer='lecun_uniform', activation='relu')(npf) - npf = Dropout(dropoutRate)(npf) - npf = Convolution1D(8, 1, kernel_initializer='lecun_uniform', activation='relu')(npf) + npf = Convolution1D(4, 1, kernel_initializer='lecun_uniform', activation='relu')(npf) npf = Flatten()(npf) vtx = Convolution1D(64, 1, kernel_initializer='lecun_uniform', activation='relu',input_shape=Inputshapes[3])(Inputs[3]) vtx = Dropout(dropoutRate)(vtx) - vtx = Convolution1D(64, 1, kernel_initializer='lecun_uniform', activation='relu')(vtx) - vtx = Dropout(dropoutRate)(vtx) - vtx = Convolution1D(32, 1, kernel_initializer='lecun_uniform', activation='relu')(vtx) - vtx = Dropout(dropoutRate)(vtx) vtx = Convolution1D(32, 1, kernel_initializer='lecun_uniform', activation='relu')(vtx) vtx = Dropout(dropoutRate)(vtx) vtx = Convolution1D(32, 1, kernel_initializer='lecun_uniform', activation='relu')(vtx) vtx = Dropout(dropoutRate)(vtx) - vtx = Convolution1D(16, 1, kernel_initializer='lecun_uniform', activation='relu')(vtx) + vtx = Convolution1D(8, 1, kernel_initializer='lecun_uniform', activation='relu')(vtx) vtx = Flatten()(vtx) x = merge( [Inputs[0],cpf,npf,vtx ] , mode='concat') - x= Dense(600, activation='relu',kernel_initializer='lecun_uniform')(x) - x = Dropout(dropoutRate)(x) - x= Dense(300, activation='relu',kernel_initializer='lecun_uniform')(x) + x= Dense(350, activation='relu',kernel_initializer='lecun_uniform')(x) x = Dropout(dropoutRate)(x) x= Dense(100, activation='relu',kernel_initializer='lecun_uniform')(x) x = Dropout(dropoutRate)(x) @@ -214,7 +202,6 @@ def Dense_model_broad(Inputs,nclasses,Inputshapes,dropoutRate=-1): x = Dropout(dropoutRate)(x) x= Dense(100, activation='relu',kernel_initializer='lecun_uniform')(x) x = Dropout(dropoutRate)(x) - x= Dense(100, activation='relu',kernel_initializer='lecun_uniform')(x) predictions = Dense(nclasses, activation='softmax',kernel_initializer='lecun_uniform')(x) model = Model(inputs=Inputs, outputs=predictions) return model @@ -282,22 +269,22 @@ def Dense_model_microPF(Inputs,nclasses,Inputshapes,dropoutRate=-1): from keras.layers.local import LocallyConnected1D - npf = Convolution1D(32, 1, kernel_initializer='lecun_uniform', activation='relu')(Inputs[1]) - npf = Dropout(dropoutRate)(npf) - npf = Convolution1D(8, 1, kernel_initializer='lecun_uniform', activation='relu')(npf) - npf = Dropout(dropoutRate)(npf) - npf = Convolution1D(4, 1, kernel_initializer='lecun_uniform', activation='relu')(npf) - npf = Dropout(dropoutRate)(npf) - npf = Flatten()(npf) + #npf = Convolution1D(32, 1, kernel_initializer='lecun_uniform', activation='relu')(Inputs[1]) + #npf = Dropout(dropoutRate)(npf) + #npf = Convolution1D(8, 1, kernel_initializer='lecun_uniform', activation='relu')(npf) + #npf = Dropout(dropoutRate)(npf) + #npf = Convolution1D(4, 1, kernel_initializer='lecun_uniform', activation='relu')(npf) + #npf = Dropout(dropoutRate)(npf) + npf = Flatten()(Inputs[1]) - x = merge( [Inputs[0],npf,Inputs[2] ] , mode='concat') + x = merge( [Inputs[0],npf] , mode='concat') - x= Dense(150, activation='relu',kernel_initializer='lecun_uniform')(x) + x= Dense(250, activation='relu',kernel_initializer='lecun_uniform')(x) x = Dropout(dropoutRate)(x) - x= Dense(100, activation='relu',kernel_initializer='lecun_uniform')(x) + x= Dense(200, activation='relu',kernel_initializer='lecun_uniform')(x) x = Dropout(dropoutRate)(x) x= Dense(100, activation='relu',kernel_initializer='lecun_uniform')(x) x = Dropout(dropoutRate)(x) @@ -314,27 +301,23 @@ def Dense_model_ConvCSV(Inputs,nclasses,Inputshape,dropoutRate=0.25): Inputs similar to 2016 training, but with covolutional layers on each track and sv """ - a = Convolution1D(32, 1, kernel_initializer='lecun_uniform', activation='relu')(Inputs[1]) + a = Convolution1D(8, 1, kernel_initializer='lecun_uniform', activation='relu')(Inputs[1]) a = Dropout(dropoutRate)(a) - a = Convolution1D(32, 1, kernel_initializer='lecun_uniform', activation='relu')(a) + a = Convolution1D(8, 1, kernel_initializer='lecun_uniform', activation='relu')(a) a = Dropout(dropoutRate)(a) a = Convolution1D(8, 1, kernel_initializer='lecun_uniform', activation='relu')(a) a = Dropout(dropoutRate)(a) a=Flatten()(a) - b = Convolution1D(1, 1, kernel_initializer='lecun_uniform', activation='relu')(Inputs[2]) - b = Dropout(dropoutRate)(b) - b =Flatten()(b) - - c = Convolution1D(32, 1, kernel_initializer='lecun_uniform', activation='relu')(Inputs[3]) + c = Convolution1D(8, 1, kernel_initializer='lecun_uniform', activation='relu')(Inputs[2]) c = Dropout(dropoutRate)(c) - c = Convolution1D(32, 1, kernel_initializer='lecun_uniform', activation='relu')(c) + c = Convolution1D(8, 1, kernel_initializer='lecun_uniform', activation='relu')(c) c = Dropout(dropoutRate)(c) c = Convolution1D(8, 1, kernel_initializer='lecun_uniform', activation='relu')(c) c = Dropout(dropoutRate)(c) c=Flatten()(c) - x = merge( [Inputs[0],a,b,c] , mode='concat') + x = merge( [Inputs[0],a,c] , mode='concat') x = Dense(100, activation='relu',kernel_initializer='lecun_uniform')(x) x = Dropout(dropoutRate)(x) @@ -342,6 +325,8 @@ def Dense_model_ConvCSV(Inputs,nclasses,Inputshape,dropoutRate=0.25): x = Dropout(dropoutRate)(x) x = Dense(100, activation='relu',kernel_initializer='lecun_uniform')(x) x = Dropout(dropoutRate)(x) + x = Dense(100, activation='relu',kernel_initializer='lecun_uniform')(x) + x = Dropout(dropoutRate)(x) x= Dense(100, activation='relu',kernel_initializer='lecun_uniform')(x) predictions = Dense(nclasses, activation='softmax',kernel_initializer='lecun_uniform')(x) model = Model(inputs=Inputs, outputs=predictions) diff --git a/modules/TrainData.py b/modules/TrainData.py index 606a5e1..5eee948 100644 --- a/modules/TrainData.py +++ b/modules/TrainData.py @@ -4,6 +4,7 @@ @author: jkiesele ''' +from __future__ import print_function from Weighter import Weighter diff --git a/modules/TrainData_deepCSV_PF.py b/modules/TrainData_deepCSV_PF.py index 5b4a5f9..771b2b8 100644 --- a/modules/TrainData_deepCSV_PF.py +++ b/modules/TrainData_deepCSV_PF.py @@ -351,34 +351,14 @@ def __init__(self): TrainData.__init__(self) - self.addBranches(['jet_pt', 'jet_eta','nCpfcand','nNpfcand','nsv','npv']) - - - - - self.addBranches(['Npfcan_pt', - 'Npfcan_ptrel', - 'Npfcan_erel', - 'Npfcan_phirel', - 'Npfcan_etarel', - 'Npfcan_deltaR', - 'Npfcan_isGamma', - 'Npfcan_HadFrac', - 'Npfcan_drminsv', - ], - 15) - - - - - #b-tag vars - self.addBranches([ 'TagVarCSV_jetNSecondaryVertices', + self.addBranches(['jet_pt', 'jet_eta','nNpfcand',#'npv', + 'TagVarCSV_jetNSecondaryVertices', 'TagVarCSV_trackSumJetEtRatio', 'TagVarCSV_trackSumJetDeltaR', 'TagVarCSV_vertexCategory', 'TagVarCSV_trackSip2dValAboveCharm', 'TagVarCSV_trackSip2dSigAboveCharm', 'TagVarCSV_trackSip3dValAboveCharm', 'TagVarCSV_trackSip3dSigAboveCharm', 'TagVarCSV_jetNSelectedTracks', 'TagVarCSV_jetNTracksEtaRel']) - + self.addBranches(['TagVarCSVTrk_trackJetDistVal', 'TagVarCSVTrk_trackPtRel', 'TagVarCSVTrk_trackDeltaR', @@ -386,7 +366,7 @@ def __init__(self): 'TagVarCSVTrk_trackSip3dSig', 'TagVarCSVTrk_trackSip2dSig', 'TagVarCSVTrk_trackDecayLenVal'], - 7) + 6) self.addBranches(['TagVarCSV_trackEtaRel'],4) @@ -403,6 +383,17 @@ def __init__(self): + self.addBranches(['Npfcan_pt', + 'Npfcan_ptrel', + 'Npfcan_erel', + 'Npfcan_phirel', + 'Npfcan_etarel', + 'Npfcan_deltaR', + 'Npfcan_isGamma', + 'Npfcan_HadFrac', + 'Npfcan_drminsv', + ], + 15) def readFromRootFile(self,filename,TupleMeanStd, weighter): @@ -426,20 +417,16 @@ def readFromRootFile(self,filename,TupleMeanStd, weighter): # split for convolutional network x_global = MeanNormZeroPad(filename,TupleMeanStd, - [self.branches[0]], - [self.branchcutoffs[0]],self.nsamples) + self.branches[0:4], + self.branchcutoffs[0:4],self.nsamples) x_npf = MeanNormZeroPadParticles(filename,TupleMeanStd, - self.branches[1], - self.branchcutoffs[1],self.nsamples) + self.branches[4], + self.branchcutoffs[4],self.nsamples) - x_global_csv = MeanNormZeroPad(filename,TupleMeanStd, - self.branches[2:], - self.branchcutoffs[2:],self.nsamples) - print('took ', sw.getAndReset(), ' seconds for mean norm and zero padding (C module)') @@ -471,7 +458,6 @@ def readFromRootFile(self,filename,TupleMeanStd, weighter): weights=weights[notremoves > 0] x_global=x_global[notremoves > 0] x_npf=x_npf[notremoves > 0] - x_global_csv=x_global_csv[notremoves > 0] alltruth=alltruth[notremoves > 0] newnsamp=x_global.shape[0] @@ -481,7 +467,7 @@ def readFromRootFile(self,filename,TupleMeanStd, weighter): print(x_global.shape,self.nsamples) self.w=[weights] - self.x=[x_global,x_npf,x_global_csv] + self.x=[x_global,x_npf] self.y=[alltruth] diff --git a/modules/TrainData_deepConvCSV.py b/modules/TrainData_deepConvCSV.py index 3965301..c0ede59 100644 --- a/modules/TrainData_deepConvCSV.py +++ b/modules/TrainData_deepConvCSV.py @@ -5,9 +5,9 @@ ''' -from TrainData_deepCSV import TrainData_deepCSV +from TrainData import TrainData_Flavour, TrainData_simpleTruth, TrainData, fileTimeOut -class TrainData_deepConvCSV(TrainData_deepCSV): +class TrainData_deepConvCSV(TrainData_Flavour, TrainData_simpleTruth): ''' classdocs ''' @@ -17,8 +17,37 @@ def __init__(self): ''' Constructor ''' - TrainData_deepCSV.__init__(self) + TrainData.__init__(self) + + self.addBranches(['jet_pt', 'jet_eta', + 'TagVarCSV_jetNSecondaryVertices', + 'TagVarCSV_trackSumJetEtRatio', 'TagVarCSV_trackSumJetDeltaR', + 'TagVarCSV_vertexCategory', 'TagVarCSV_trackSip2dValAboveCharm', + 'TagVarCSV_trackSip2dSigAboveCharm', 'TagVarCSV_trackSip3dValAboveCharm', + 'TagVarCSV_trackSip3dSigAboveCharm', 'TagVarCSV_jetNSelectedTracks', + 'TagVarCSV_jetNTracksEtaRel']) + + self.addBranches(['TagVarCSVTrk_trackJetDistVal', + 'TagVarCSVTrk_trackPtRel', + 'TagVarCSVTrk_trackDeltaR', + 'TagVarCSVTrk_trackPtRatio', + 'TagVarCSVTrk_trackSip3dSig', + 'TagVarCSVTrk_trackSip2dSig', + 'TagVarCSVTrk_trackDecayLenVal', + 'TagVarCSV_trackEtaRel'], + 6) + + + self.addBranches(['TagVarCSV_vertexMass', + 'TagVarCSV_vertexNTracks', + 'TagVarCSV_vertexEnergyRatio', + 'TagVarCSV_vertexJetDeltaR', + 'TagVarCSV_flightDistance2dVal', + 'TagVarCSV_flightDistance2dSig', + 'TagVarCSV_flightDistance3dVal', + 'TagVarCSV_flightDistance3dSig'], + 1) @@ -43,8 +72,8 @@ def readFromRootFile(self,filename,TupleMeanStd, weighter): # split for convolutional network x_global = MeanNormZeroPad(filename,TupleMeanStd, - self.branches[0], - self.branchcutoffs[0],self.nsamples) + [self.branches[0]], + [self.branchcutoffs[0]],self.nsamples) x_a = MeanNormZeroPadParticles(filename,TupleMeanStd, @@ -56,9 +85,6 @@ def readFromRootFile(self,filename,TupleMeanStd, weighter): self.branchcutoffs[2],self.nsamples) - x_c = MeanNormZeroPadParticles(filename,TupleMeanStd, - self.branches[3], - self.branchcutoffs[3],self.nsamples) @@ -92,7 +118,6 @@ def readFromRootFile(self,filename,TupleMeanStd, weighter): x_global=x_global[notremoves > 0] x_a=x_a[notremoves > 0] x_b=x_b[notremoves > 0] - x_c=x_c[notremoves > 0] alltruth=alltruth[notremoves > 0] newnsamp=x_global.shape[0] @@ -102,5 +127,5 @@ def readFromRootFile(self,filename,TupleMeanStd, weighter): print(x_global.shape,self.nsamples) self.w=[weights] - self.x=[x_global,x_a,x_b,x_c] + self.x=[x_global,x_a,x_b] self.y=[alltruth] \ No newline at end of file diff --git a/modules/Weighter.py b/modules/Weighter.py index f982413..3ee0328 100644 --- a/modules/Weighter.py +++ b/modules/Weighter.py @@ -4,6 +4,8 @@ @author: jkiesele ''' +from __future__ import print_function + class Weighter(object): ''' contains the histograms/input to calculate jet-wise weights diff --git a/modules/testing.py b/modules/testing.py index 491fa82..70c66c3 100644 --- a/modules/testing.py +++ b/modules/testing.py @@ -19,6 +19,8 @@ # # +from __future__ import print_function + class testDescriptor(object): def __init__(self):