# RegressionKeras example

**URL:** <https://root-forum.cern.ch/t/regressionkeras-example/43466>\
**Category:** TMVA\
**Created:** [February 9, 2021, 2:32pm UTC](https://root-forum.cern.ch/t/regressionkeras-example/43466 "2021-02-09T14:32:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![testa](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/t/958977/32.png) [@testa](https://root-forum.cern.ch/u/testa)\
**Post date:** [February 9, 2021, 2:32pm UTC](https://root-forum.cern.ch/t/regressionkeras-example/43466/1 "2021-02-09T14:32:40Z")

</div>

Dear experts,  
I would like to run this example:  
[https://root.cern.ch/doc/v622/RegressionKeras\_8py\_source.html](https://root.cern.ch/doc/v622/RegressionKeras_8py_source.html)

On lxplus I did:

source /cvmfs/sft.cern.ch/lcg/views/LCG\_98python3/x86\_64-centos7-gcc8-opt/setup.sh  
[mtesta@lxplus759 ML\_setup]$ python  
Python 3.7.6 (default, Aug 12 2020, 09:46:40)  
[GCC 8.3.0] on linux  
Type “help”, “copyright”, “credits” or “license” for more information.

> > > from ROOT import TMVA, TFile, TTree, TCut

It’s stuck here. The culprit seems “from ROOT import TFile”

Am I doing something wrong in the setup?

Is there an instruction how to run this example?

Best, Marianna.

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [February 9, 2021, 3:41pm UTC](https://root-forum.cern.ch/t/regressionkeras-example/43466/2 "2021-02-09T15:41:45Z")

</div>

Hi Marianna,  
on lxplus it can take a while to read the files from CMVS that are required to import ROOT – a while as in, 30 seconds max, and typically only the first time you run that script.

I just tried myself:

```auto
[eguiraud@lxplus727 ~]$ source /cvmfs/sft.cern.ch/lcg/views/LCG_98python3/x86_64-centos7-gcc8-opt/setup.sh
[eguiraud@lxplus727 ~]$ python
Python 3.7.6 (default, Aug 12 2020, 09:46:40) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from ROOT import TMVA
>>> from ROOT import TFile
Error in <RootX11ErrorHandler>: BadAccess (attempt to access private resource denied) (XID: 418, XREQ: 18)
>>> 

```

That last error message should not be there, there is something wrong with this LCG view.

To work around the issue you can use a different LCG view, e.g. `/cvmfs/sft.cern.ch/lcg/views/LCG_99/x86_64-centos7-gcc8-opt/setup.sh` works.

I’ll report the problem with LCG\_98python3 upstream.

Cheers,  
Enrico

---

<div class="post-metadata">

**Author:** ![testa](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/t/958977/32.png) [@testa](https://root-forum.cern.ch/u/testa)\
**Post date:** [February 9, 2021, 4:00pm UTC](https://root-forum.cern.ch/t/regressionkeras-example/43466/3 "2021-02-09T16:00:14Z")

</div>

Hi Enrico,  
I find out that using the -Y option when connecting: ssh -Y lxplus.cern.ch  
makes the `“from ROOT import TFile” command stucking, also with LCG\_99  
Can this be fixed?  
Best, Marianna.

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [February 9, 2021, 4:06pm UTC](https://root-forum.cern.ch/t/regressionkeras-example/43466/4 "2021-02-09T16:06:15Z")

</div>

Uhm it goes through fine for me:

```auto
~ ssh -Y eguiraud@lxplus.cern.ch
Warning: Permanently added the ECDSA host key for IP address '188.185.91.62' to the list of known hosts.
Password: 
* ********************************************************************
* Welcome to lxplus7117.cern.ch, CentOS, 7.9.2009
* Archive of news is available in /etc/motd-archive
* Reminder: you have agreed to the CERN
* computing rules, in particular OC5. CERN implements
* the measures necessary to ensure compliance.
* https://cern.ch/ComputingRules
* Puppet environment: production, Roger state: production
* Foreman hostgroup: lxplus/nodes/login
* Availability zone: cern-geneva-c
* LXPLUS Public Login Service - http://lxplusdoc.web.cern.ch/
* A C8 based lxplus8.cern.ch is now available
* Please read LXPLUS Privacy Notice in http://cern.ch/go/TpV7
* ********************************************************************
[eguiraud@lxplus7117 ~]$ source /cvmfs/sft.cern.ch/lcg/views/LCG_99/x86_64-centos7-gcc8-opt/setup.sh
[eguiraud@lxplus7117 ~]$ python
Python 3.8.6 (default, Dec 11 2020, 21:39:59) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from ROOT import TFile
>>> 
>>> 

```

Not sure what might be happening 😕

---

<div class="post-metadata">

**Author:** ![testa](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/t/958977/32.png) [@testa](https://root-forum.cern.ch/u/testa)\
**Post date:** [February 9, 2021, 4:19pm UTC](https://root-forum.cern.ch/t/regressionkeras-example/43466/5 "2021-02-09T16:19:03Z")

</div>

HI, may be it depends on my remote connection…

Could you please try to run the full file?  
I get error  
AttributeError: module ‘tensorflow’ has no attribute ‘get\_default\_graph’

(full log attached)[log\_regressionkeras.txt](https://root-forum.cern.ch/uploads/short-url/wXpa5ifY2A6z1Z6bIdWZGUBL20U.txt) (1.6 KB)

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [February 9, 2021, 4:29pm UTC](https://root-forum.cern.ch/t/regressionkeras-example/43466/6 "2021-02-09T16:29:58Z")

</div>

Ah indeed, I can reproduce that one!

```auto
[eguiraud@lxplus700 ~]$ source /cvmfs/sft.cern.ch/lcg/views/LCG_99/x86_64-centos7-gcc8-opt/setup.sh
[eguiraud@lxplus700 ~]$ python $(root-config --tutdir)/tmva/keras/RegressionKeras.py
Using TensorFlow backend.
  % Total % Received % Xferd Average Speed Time Time Time Current
                                 Dload Upload Total Spent Left Speed
100 110k 100 110k 0 0 14.2M 0 --:--:-- --:--:-- --:--:-- 15.4M
DataSetInfo : [dataset] : Added class "Regression"
                         : Add Tree TreeR of type Regression with 10000 events
                         : Dataset[dataset] : Class index : 0 name : Regression
Traceback (most recent call last):
  File "/cvmfs/sft.cern.ch/lcg/releases/ROOT/v6.22.06-1d426/x86_64-centos7-gcc8-opt/tutorials/tmva/keras/RegressionKeras.py", line 51, in <module>
    model = Sequential()
  File "/cvmfs/sft.cern.ch/lcg/views/LCG_99/x86_64-centos7-gcc8-opt/lib/python3.8/site-packages/keras/engine/sequential.py", line 87, in __init__
    super(Sequential, self). __init__ (name=name)
  File "/cvmfs/sft.cern.ch/lcg/views/LCG_99/x86_64-centos7-gcc8-opt/lib/python3.8/site-packages/keras/legacy/interfaces.py", line 91, in wrapper
    return func(*args, **kwargs)
  File "/cvmfs/sft.cern.ch/lcg/views/LCG_99/x86_64-centos7-gcc8-opt/lib/python3.8/site-packages/keras/engine/network.py", line 96, in __init__
    self._init_subclassed_network(**kwargs)
  File "/cvmfs/sft.cern.ch/lcg/views/LCG_99/x86_64-centos7-gcc8-opt/lib/python3.8/site-packages/keras/engine/network.py", line 294, in _init_subclassed_network
    self._base_init(name=name)
  File "/cvmfs/sft.cern.ch/lcg/views/LCG_99/x86_64-centos7-gcc8-opt/lib/python3.8/site-packages/keras/engine/network.py", line 109, in _base_init
    name = prefix + '_' + str(K.get_uid(prefix))
  File "/cvmfs/sft.cern.ch/lcg/views/LCG_99/x86_64-centos7-gcc8-opt/lib/python3.8/site-packages/keras/backend/tensorflow_backend.py", line 74, in get_uid
    graph = tf.get_default_graph()
AttributeError: module 'tensorflow' has no attribute 'get_default_graph'

```

I’m not sure whether it’s a problem with the tutorial code or with the LCG release, we need @moneta .

---

<div class="post-metadata">

**Author:** ![testa](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/t/958977/32.png) [@testa](https://root-forum.cern.ch/u/testa)\
**Post date:** [February 15, 2021, 8:15am UTC](https://root-forum.cern.ch/t/regressionkeras-example/43466/7 "2021-02-15T08:15:16Z")

</div>

Hello, any chance to have some help on that?  
Best, Marianna.

---

<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:** [February 17, 2021, 6:30pm UTC](https://root-forum.cern.ch/t/regressionkeras-example/43466/8 "2021-02-17T18:30:06Z")

</div>

Hi,

This is cause by an incompatibility between keras and tensorflow in LCG 99. With tensorflow 2 you need either to use keras 2.3 or tensorflow.keras (recommended solution).  
We need to fix the tutorials in ROOT for tf.keras.

Best regards

Lorenzo
