Issue with Custom Metrics in TMVA

As I understand it, the way to use keras with TMVA is to define a model in Keras, save it to a file, then use TMVA factory.BookMethod() to import the model from the file. The issue with this is that when importing models from file in keras that use a custom metric, you have to specify the custom metrics with something like load_model(modelPath, custom_objects={'mean_squared_abs_error': mean_squared_abs_error}), and since the only option I can find in factory.BookMethod() is to list the filename of the model, this doesn’t seem possible. How do I use a model with custom metrics in TMVA?


Unfortunately you cannot use custom metrics with the Keras interface of TMVA. You would have to import the Python callable of the custom metric in the interpreter runtime of PyMVA (which is not possible). PyMVA does actually fire up an own Python interpreter instance in the back, completely separated from the interpreter instance, where you’ve declared your model with the custom metric.

Best regards