# TMVA TensorFlow Keras interface with python3

**URL:** <https://root-forum.cern.ch/t/tmva-tensorflow-keras-interface-with-python3/41675>\
**Category:** TMVA\
**Created:** [October 2, 2020, 9:52am UTC](https://root-forum.cern.ch/t/tmva-tensorflow-keras-interface-with-python3/41675 "2020-10-02T09:52:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![angirar](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/d9b06d/32.png) [@angirar](https://root-forum.cern.ch/u/angirar)\
**Post date:** [October 2, 2020, 9:52am UTC](https://root-forum.cern.ch/t/tmva-tensorflow-keras-interface-with-python3/41675/1 "2020-10-02T09:52:34Z")

</div>

Hello,

I am trying to load a TensorFlow Keras model file (in h5 format) using the BookMethod and type as “PyKerasNN”. But this seems to be crashing [1]. This has worked with plain Keras but doesn’t work with TensorFlow Keras. My versions are ROOT 6.22/00, TensorFlow 2.1.0 and python 3.7.6.

I think it is coming from the TMVA::MethodPyKeras class where TMVA calls the ‘Keras.models.load\_model’ [2]. This seems to conflict with python3 as keras is now integrated into TensorFlow. On lxplus, only tensor flow keras is supported starting from python3.

Could you please look into this and do the possible fix? Please let me know if you need any other information from my side.

Best,  
Angira

[1] - Part of the error message is pasted here -  
: Using TensorFlow backend - setting special configuration options  
: Using Tensorflow version 2  
 : Failed to run python code: model = keras.models.load\_model(‘model.h5’)

[2] - [https://github.com/root-project/root/blob/master/tmva/pymva/src/MethodPyKeras.cxx#L267](https://github.com/root-project/root/blob/master/tmva/pymva/src/MethodPyKeras.cxx#L267)

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [October 2, 2020, 1:17pm UTC](https://root-forum.cern.ch/t/tmva-tensorflow-keras-interface-with-python3/41675/2 "2020-10-02T13:17:15Z")

</div>

Hi,

Which Keras version are you using ? You should update to a version larger than 2.3.0 the first one compatible with Tensorflow 2, see [https://github.com/keras-team/keras/releases/tag/2.3.0](https://github.com/keras-team/keras/releases/tag/2.3.0)

Curently MethodPyKeras is not compatible directly with Keras API of Tensorflow ( tf.keras), but we are planning to support this. How are you getting Tensorflow in lxplus, from cvmfs ?

Best

Lorenzo

---

<div class="post-metadata">

**Author:** ![angirar](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/d9b06d/32.png) [@angirar](https://root-forum.cern.ch/u/angirar)\
**Post date:** [October 5, 2020, 5:17am UTC](https://root-forum.cern.ch/t/tmva-tensorflow-keras-interface-with-python3/41675/3 "2020-10-05T05:17:51Z")

</div>

Hi Lorenzo,

Thank you for your response, sorry for my late reply.  
Indeed I get Tensorflow 2.3.1 from cvmfs [1] on lxplus. The Keras API version implemented in tensorflow is 2.2.4.  
These are centrally installed on lxplus and I don’t have direct privileges to update them 😃

Regards,  
Angira

[1] - /cvmfs/sft.cern.ch/lcg/views/LCG\_98python3/x86\_64-centos7-gcc8-opt/setup.sh

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [October 5, 2020, 1:24pm UTC](https://root-forum.cern.ch/t/tmva-tensorflow-keras-interface-with-python3/41675/4 "2020-10-05T13:24:18Z")

</div>

Hi,  
I have opened a github issue on this to update ROOT for `tf.keras`  
See [https://github.com/root-project/root/issues/6553](https://github.com/root-project/root/issues/6553)

Lorenzo
