diff --git a/math/mathcore/src/FitUtil.cxx b/math/mathcore/src/FitUtil.cxx index 0ce72380d67bb..f3d34e788d104 100644 --- a/math/mathcore/src/FitUtil.cxx +++ b/math/mathcore/src/FitUtil.cxx @@ -1118,7 +1118,7 @@ double FitUtil::EvaluateLogL(const IModelFunction &func, const UnBinData &data, } else { // use (-inf +inf) data.Range().GetRange(&xmin[0],&xmax[0]); - // check if funcition is zero at +- inf + // check if function is zero at +- inf if (func(xmin.data(), p) != 0 || func(xmax.data(), p) != 0) { MATH_ERROR_MSG("FitUtil::EvaluateLogLikelihood","A range has not been set and the function is not zero at +/- inf"); return 0; diff --git a/tmva/pymva/test/EmitCustomModel.cxx b/tmva/pymva/test/EmitCustomModel.cxx index 2141b98bad5fb..fa4071d1a6cad 100644 --- a/tmva/pymva/test/EmitCustomModel.cxx +++ b/tmva/pymva/test/EmitCustomModel.cxx @@ -34,7 +34,7 @@ y_train=randomGenerator.rand(1,4)\n\ \n\ model.compile(loss='mean_squared_error', optimizer=SGD(learning_rate=0.01))\n\ model.fit(x_train, y_train, epochs=10, batch_size=1)\n\ -model.save('KerasModelForCustomOp.keras')\n"; +model.save('KerasModelForCustomOp.h5')\n"; int main(){ Py_Initialize(); @@ -43,7 +43,7 @@ int main(){ PyRun_SimpleString(pythonSrc); //Parsing the saved Keras .keras file into RModel object - RModel model = PyKeras::Parse("KerasModelForCustomOp.keras"); + RModel model = PyKeras::Parse("KerasModelForCustomOp.h5"); model.Generate(); std::unique_ptr op; diff --git a/tmva/pymva/test/EmitFromKeras.cxx b/tmva/pymva/test/EmitFromKeras.cxx index 4d6291e97f1b7..bbaf8018add6d 100644 --- a/tmva/pymva/test/EmitFromKeras.cxx +++ b/tmva/pymva/test/EmitFromKeras.cxx @@ -21,54 +21,54 @@ int main(){ PyRun_SimpleFile(fKerasModels, "generateKerasModels.py"); //Emitting header file for Keras Sequential Model - RModel modelSequential = TMVA::Experimental::SOFIE::PyKeras::Parse("KerasModelSequential.keras"); + RModel modelSequential = TMVA::Experimental::SOFIE::PyKeras::Parse("KerasModelSequential.h5"); modelSequential.Generate(); modelSequential.OutputGenerated("KerasSequentialModel.hxx"); //Emitting header file for Keras Functional API Model - RModel modelFunctional = TMVA::Experimental::SOFIE::PyKeras::Parse("KerasModelFunctional.keras"); + RModel modelFunctional = TMVA::Experimental::SOFIE::PyKeras::Parse("KerasModelFunctional.h5"); modelFunctional.Generate(); modelFunctional.OutputGenerated("KerasFunctionalModel.hxx"); //Emitting header file for Keras BatchNorm Model - RModel modelBatchNorm = TMVA::Experimental::SOFIE::PyKeras::Parse("KerasModelBatchNorm.keras"); + RModel modelBatchNorm = TMVA::Experimental::SOFIE::PyKeras::Parse("KerasModelBatchNorm.h5"); modelBatchNorm.Generate(); modelBatchNorm.OutputGenerated("KerasBatchNormModel.hxx"); #if PY_MAJOR_VERSION >= 3 // parsing of convolutional models supported only for Python3 // Emitting header file for Keras Conv2D Model with valid padding - RModel modelConv2D_Valid = TMVA::Experimental::SOFIE::PyKeras::Parse("KerasModelConv2D_Valid.keras"); + RModel modelConv2D_Valid = TMVA::Experimental::SOFIE::PyKeras::Parse("KerasModelConv2D_Valid.h5"); modelConv2D_Valid.Generate(); modelConv2D_Valid.OutputGenerated("KerasConv2D_Valid.hxx"); // Emitting header file for Keras Conv2D Model with valid padding - RModel modelConv2D_Same = TMVA::Experimental::SOFIE::PyKeras::Parse("KerasModelConv2D_Same.keras"); + RModel modelConv2D_Same = TMVA::Experimental::SOFIE::PyKeras::Parse("KerasModelConv2D_Same.h5"); modelConv2D_Same.Generate(); modelConv2D_Same.OutputGenerated("KerasConv2D_Same.hxx"); #endif //Emitting header file for Keras model with Reshape layer - RModel modelReshape = TMVA::Experimental::SOFIE::PyKeras::Parse("KerasModelReshape.keras"); + RModel modelReshape = TMVA::Experimental::SOFIE::PyKeras::Parse("KerasModelReshape.h5"); modelReshape.Generate(); modelReshape.OutputGenerated("KerasReshapeModel.hxx"); //Emitting header file for Keras model with Concatenate layer - RModel modelConcatenate = TMVA::Experimental::SOFIE::PyKeras::Parse("KerasModelConcatenate.keras"); + RModel modelConcatenate = TMVA::Experimental::SOFIE::PyKeras::Parse("KerasModelConcatenate.h5"); modelConcatenate.Generate(); modelConcatenate.OutputGenerated("KerasConcatenateModel.hxx"); // Emitting header file for Keras Binary Op Model - RModel modelBinaryOp = TMVA::Experimental::SOFIE::PyKeras::Parse("KerasModelBinaryOp.keras"); + RModel modelBinaryOp = TMVA::Experimental::SOFIE::PyKeras::Parse("KerasModelBinaryOp.h5"); modelBinaryOp.Generate(); modelBinaryOp.OutputGenerated("KerasBinaryOpModel.hxx"); //Emitting header file for Keras activation functions model - RModel modelActivations = TMVA::Experimental::SOFIE::PyKeras::Parse("KerasModelActivations.keras"); + RModel modelActivations = TMVA::Experimental::SOFIE::PyKeras::Parse("KerasModelActivations.h5"); modelActivations.Generate(); modelActivations.OutputGenerated("KerasActivationsModel.hxx"); // Emitting header file for Swish activation functions model - RModel modelSwish = TMVA::Experimental::SOFIE::PyKeras::Parse("swish_model.keras"); + RModel modelSwish = TMVA::Experimental::SOFIE::PyKeras::Parse("swish_model.h5"); modelSwish.Generate(); modelSwish.OutputGenerated("KerasSwish_model.hxx"); diff --git a/tmva/pymva/test/generateKerasModels.py b/tmva/pymva/test/generateKerasModels.py index 271d547e57db2..92fd13baac21c 100644 --- a/tmva/pymva/test/generateKerasModels.py +++ b/tmva/pymva/test/generateKerasModels.py @@ -24,7 +24,7 @@ def generateFunctionalModel(): model.compile(loss='mean_squared_error', optimizer=SGD(learning_rate=0.01)) model.fit(x_train, y_train, epochs=10, batch_size=2) - model.save('KerasModelFunctional.keras') + model.save('KerasModelFunctional.h5') def generateSequentialModel(): model=Sequential() @@ -39,7 +39,7 @@ def generateSequentialModel(): model.compile(loss='mean_squared_error', optimizer=SGD(learning_rate=0.01)) model.fit(x_train, y_train, epochs=10, batch_size=4) - model.save('KerasModelSequential.keras') + model.save('KerasModelSequential.h5') def generateBatchNormModel(): model=Sequential() @@ -53,7 +53,7 @@ def generateBatchNormModel(): model.compile(loss='mean_squared_error', optimizer=SGD(learning_rate=0.01)) model.fit(x_train, y_train, epochs=10, batch_size=2) - model.save('KerasModelBatchNorm.keras') + model.save('KerasModelBatchNorm.h5') def generateConv2DModel_ValidPadding(): model=Sequential() @@ -65,7 +65,7 @@ def generateConv2DModel_ValidPadding(): model.compile(loss='mean_squared_error', optimizer=SGD(learning_rate=0.01)) model.fit(x_train, y_train, epochs=10, batch_size=2) - model.save('KerasModelConv2D_Valid.keras') + model.save('KerasModelConv2D_Valid.h5') def generateConv2DModel_SamePadding(): model=Sequential() @@ -77,7 +77,7 @@ def generateConv2DModel_SamePadding(): model.compile(loss='mean_squared_error', optimizer=SGD(learning_rate=0.01)) model.fit(x_train, y_train, epochs=10, batch_size=2) - model.save('KerasModelConv2D_Same.keras') + model.save('KerasModelConv2D_Same.h5') def generateReshapeModel(): model = Sequential() @@ -90,7 +90,7 @@ def generateReshapeModel(): model.compile(loss='mean_squared_error', optimizer=SGD(learning_rate=0.01)) model.fit(x_train, y_train, epochs=10, batch_size=2) - model.save('KerasModelReshape.keras') + model.save('KerasModelReshape.h5') def generateConcatModel(): input_1 = Input(shape=(2,)) @@ -107,7 +107,7 @@ def generateConcatModel(): model.compile(loss='mean_squared_error', optimizer=SGD(learning_rate=0.01)) model.fit([x1_train,x2_train], y_train, epochs=10, batch_size=1) - model.save('KerasModelConcatenate.keras') + model.save('KerasModelConcatenate.h5') def generateBinaryOpModel(): input1 = Input(shape=(2, )) @@ -124,7 +124,7 @@ def generateBinaryOpModel(): model.compile(loss='mean_squared_error', optimizer=SGD(learning_rate=0.01)) model.fit([x1_train,x2_train], y_train, epochs=10, batch_size=2) - model.save('KerasModelBinaryOp.keras') + model.save('KerasModelBinaryOp.h5') def generateActivationModel(): input=Input(shape=(8,)) @@ -140,7 +140,7 @@ def generateActivationModel(): model.compile(loss='mean_squared_error', optimizer=SGD(learning_rate=0.01)) model.fit(x_train, y_train, epochs=10, batch_size=1) - model.save('KerasModelActivations.keras') + model.save('KerasModelActivations.h5') def generateSwishModel(): # Create the Keras model @@ -153,7 +153,7 @@ def generateSwishModel(): optimizer='adam', metrics=['accuracy']) # Save the model as an.keras file - model.save('swish_model.keras') + model.save('swish_model.h5') generateFunctionalModel() diff --git a/tmva/pymva/test/testPyKerasClassification.C b/tmva/pymva/test/testPyKerasClassification.C index 63aecacd2b8ae..0634bc52b2a88 100644 --- a/tmva/pymva/test/testPyKerasClassification.C +++ b/tmva/pymva/test/testPyKerasClassification.C @@ -30,19 +30,20 @@ int testPyKerasClassification(){ TFile *input = TFile::Open(fname); // Build model from python file - std::cout << "Generate keras model..." << std::endl; - UInt_t ret; - ret = gSystem->Exec("echo '"+pythonSrc+"' > generateKerasModelClassification.py"); - if(ret!=0){ - std::cout << "[ERROR] Failed to write python code to file" << std::endl; - return 1; + if (gSystem->AccessPathName("kerasModelClassification.h5")) { + std::cout << "Generate keras model..." << std::endl; + UInt_t ret; + ret = gSystem->Exec("echo '"+pythonSrc+"' > generateKerasModelClassification.py"); + if(ret!=0){ + std::cout << "[ERROR] Failed to write python code to file" << std::endl; + return 1; + } + ret = gSystem->Exec(TMVA::Python_Executable() + " generateKerasModelClassification.py"); + if(ret!=0){ + std::cout << "[ERROR] Failed to generate model using python" << std::endl; + return 1; + } } - ret = gSystem->Exec(TMVA::Python_Executable() + " generateKerasModelClassification.py"); - if(ret!=0){ - std::cout << "[ERROR] Failed to generate model using python" << std::endl; - return 1; - } - // Setup PyMVA and factory std::cout << "Setup TMVA..." << std::endl; TMVA::PyMethodBase::PyInitialize();