# TMVA\_SOFIE\_Keras on MacOS

**URL:** <https://root-forum.cern.ch/t/tmva-sofie-keras-on-macos/52551>\
**Category:** TMVA\
**Tags:** python, tmva\
**Created:** [November 29, 2022, 10:29pm UTC](https://root-forum.cern.ch/t/tmva-sofie-keras-on-macos/52551 "2022-11-29T22:29:05Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dave\_Brown](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/c37758/32.png) [@Dave\_Brown](https://root-forum.cern.ch/u/Dave_Brown)\
**Post date:** [November 29, 2022, 10:29pm UTC](https://root-forum.cern.ch/t/tmva-sofie-keras-on-macos/52551/1 "2022-11-29T22:29:05Z")

</div>

I’m trying to run the TMVA\_SOFIE\_Keras.C tutorial on MacOSX (Monterey 12.6, i9). I’ve installed a python-aware version of root 6.26.10 using mamba, which seems to work normally. The problem is listed below. It runs fine on a linux-based machine following the same install procedure.

root [0] .x /Applications/root\_v6.26.10/tutorials/tmva/TMVA\_SOFIE\_Keras.C  
cling::DynamicLibraryManager::loadLibrary(): dlopen(/Users/brownd/mambaforge/envs/KKTrain/lib/libPyMVA.6.26.10.so, 0x0009): symbol not found in flat namespace (\_PyCapsule\_Type)  
Error in \<TCling\_\_LazyFunctionCreatorAutoloadForModule\>: Failed to load library /Users/brownd/mambaforge/envs/KKTrain/lib/libPyMVA.6.26.10.so

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [November 30, 2022, 7:18am UTC](https://root-forum.cern.ch/t/tmva-sofie-keras-on-macos/52551/2 "2022-11-30T07:18:46Z")

</div>

Maybe @moneta or @vpadulan can help.

---

<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:** [December 1, 2022, 9:57pm UTC](https://root-forum.cern.ch/t/tmva-sofie-keras-on-macos/52551/3 "2022-12-01T21:57:11Z")

</div>

Hi Dave,

it looks like th library `libPyMVA` is not there. You should use a build with `tmva-pymva=On` and you can check if the feature is there by typing on the command line.

```auto
root-config --has-tmva-pymva

```

Normally the feature is on when you have a valid Python and numpy version.

Cheers

Lorenzo

Lorenzo

---

<div class="post-metadata">

**Author:** ![Dave\_Brown](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/c37758/32.png) [@Dave\_Brown](https://root-forum.cern.ch/u/Dave_Brown)\
**Post date:** [December 6, 2022, 11:45pm UTC](https://root-forum.cern.ch/t/tmva-sofie-keras-on-macos/52551/4 "2022-12-06T23:45:08Z")

</div>

Hi Lorenzo,  
libPyMVA is present in my OSX root build:  
KKTrain % root-config --has-tmva-pymva  
yes

The problem can be replicated with a simple test:  
root [0] .L $ROOTSYS/lib/libPyMVA.so  
cling::DynamicLibraryManager::loadLibrary(): dlopen(/Users/brownd/mambaforge-pypy3/lib/[libPyMVA.6.26.08.so](http://libPyMVA.6.26.08.so), 0x0009): symbol not found in flat namespace (\_PyCapsule\_Type)

---

<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:** [December 7, 2022, 8:28am UTC](https://root-forum.cern.ch/t/tmva-sofie-keras-on-macos/52551/5 "2022-12-07T08:28:06Z")

</div>

This is strange, it looks like `libPyMVA.so` has not been build correctly.  
Can you run the tests in `tmva/pymva/test` or the tutorial `tutorials/tmva/TMVA_CNN_Classification.C` ?

Cheers

Lorenzo

---

<div class="post-metadata">

**Author:** ![Jackhammer0102](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/e5b9ba/32.png) [@Jackhammer0102](https://root-forum.cern.ch/u/Jackhammer0102)\
**Post date:** [April 5, 2023, 4:01am UTC](https://root-forum.cern.ch/t/tmva-sofie-keras-on-macos/52551/6 "2023-04-05T04:01:04Z")

</div>

Hi, Lorenzo,

I got similar errors as @Dave_Brown has described in this post when I was trying to run the macro **tutorials/tmva/TMVA\_CNN\_Classification.C**

Here are the errors I got:

```auto
cling::DynamicLibraryManager::loadLibrary(): dlopen(/Users/martin/opt/anaconda3/envs/tensorflow/lib/libPyMVA.6.28.00.so, 0x0009): symbol not found in flat namespace '_PyCapsule_Type'
Error in <AutoloadLibraryMU>: Failed to load library /Users/martin/opt/anaconda3/envs/tensorflow/lib/libPyMVA.6.28.00.socling JIT session error: Failed to materialize symbols: { (main, { __ZN4TMVA12PyMethodBase12PyInitializeEv }) }

```

Is there a solution to this problem?

P.S.  
I got a **“yes”** when I did `root-config --has-tmva-pymva` in the terminal.

---

<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:** [April 5, 2023, 7:10am UTC](https://root-forum.cern.ch/t/tmva-sofie-keras-on-macos/52551/7 "2023-04-05T07:10:05Z")

</div>

Hi,  
It looks like then there is an issue for some builds of libPyMVA. Can you tell me exactly the configuration you are using, ROOT version, Python version, Numpy version, tensorflow version and how did you build ROOT, etc…, so I can reproduce the problem

Lorenzo

---

<div class="post-metadata">

**Author:** ![Jackhammer0102](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/e5b9ba/32.png) [@Jackhammer0102](https://root-forum.cern.ch/u/Jackhammer0102)\
**Post date:** [April 5, 2023, 4:45pm UTC](https://root-forum.cern.ch/t/tmva-sofie-keras-on-macos/52551/8 "2023-04-05T16:45:47Z")

</div>

Hi, Lorenzo,

These are the information about my system:

> ROOT Version: 6.28/00
> 
> Python Platform: macOS-12.4-x86\_64-i386-64bit
> 
> Tensor Flow Version: 2.12.0
> 
> Keras Version: 2.12.0
> 
> Python 3.10.10 | packaged by conda-forge | (main, Mar 24 2023, 20:17:34) [Clang 14.0.6]
> 
> Numpy 1.23.5
> 
> Pandas 2.0.0
> 
> Scikit-Learn 1.2.2
> 
> GPU is available

And this is how I installed TensorFlow and ROOT on my Mac:

> 1. Installed **Anaconda**
> 
> 2. Installed **TensorFlow** by doing this command in the terminal:  
> `conda env create -f tensorflow-apple-metal.yml -n tensorflow`
> 
> In my **tensorflow-apple-metal.yml** file:
> 
> name: tensorflow  
> channels:
> 
> - apple
> - conda-forge  
> dependencies:
> - python=3.10
> - pip\>=19.0
> - jupyter
> - scikit-learn
> - scipy
> - pandas
> - pandas-datareader
> - matplotlib
> - pillow
> - tqdm
> - requests
> - h5py
> - pyyaml
> - flask
> - boto3
> - ipykernel
> - pip:
> - tensorflow-macos
> - tensorflow-metal
> - bayesian-optimization
> - gym
> - kaggle
> 
> Then I did
> 
> 1. `conda activate tensorflow`
> 
> 2. `python -m ipykernel install --user --name tensorflow --display-name "Python 3.10 (tensorflow)"`
> 
> 3. Installed ROOT in the environment by using this command:  
> `conda install root -c conda-forge`

I ran the macro **tutorials/tmva/make\_cnn\_model.py** to get the output file **model\_cnn.h5** , and then in ROOT I did:

```auto
root [0] .x TMVA_CNN_Classification.C

```

Then I got the errors:

```auto
cling::DynamicLibraryManager::loadLibrary(): dlopen(/Users/martin/opt/anaconda3/envs/tensorflow/lib/libPyMVA.6.28.00.so, 0x0009): symbol not found in flat namespace '_PyCapsule_Type'
Error in <AutoloadLibraryMU>: Failed to load library /Users/martin/opt/anaconda3/envs/tensorflow/lib/libPyMVA.6.28.00.socling JIT session error: Failed to materialize symbols: { (main, { __ZN4TMVA12PyMethodBase12PyInitializeEv }) }

```

---

<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:** [April 6, 2023, 7:18am UTC](https://root-forum.cern.ch/t/tmva-sofie-keras-on-macos/52551/9 "2023-04-06T07:18:18Z")

</div>

Hi,

Thank you for the information, it is maybe an issue with the ROOT conda builds on MacOS. I will test this and let you know

Cheers

Lorenzo

---

<div class="post-metadata">

**Author:** ![Jackhammer0102](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/e5b9ba/32.png) [@Jackhammer0102](https://root-forum.cern.ch/u/Jackhammer0102)\
**Post date:** [April 6, 2023, 9:59pm UTC](https://root-forum.cern.ch/t/tmva-sofie-keras-on-macos/52551/10 "2023-04-06T21:59:35Z")

</div>

Sounds good, I appreciate it and thank you!

---

<div class="post-metadata">

**Author:** ![Jackhammer0102](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/e5b9ba/32.png) [@Jackhammer0102](https://root-forum.cern.ch/u/Jackhammer0102)\
**Post date:** [April 8, 2023, 7:18am UTC](https://root-forum.cern.ch/t/tmva-sofie-keras-on-macos/52551/11 "2023-04-08T07:18:40Z")

</div>

I’ve found another way to make the macro run successfully with Keras on my Mac but it has to be in Python, so I saw the macro **TMVA\_CNN\_Classification.py** , the Python version of this CNN script, and then I ran the macro directly in Python3 interface without going through the ROOT interface, and it worked.

---

<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:** [April 11, 2023, 7:52am UTC](https://root-forum.cern.ch/t/tmva-sofie-keras-on-macos/52551/12 "2023-04-11T07:52:47Z")

</div>

Hi,  
It is good that using Python the macro `TMVA_CNN_Classification.py` works and the C++ version, `TMVA_CNN_Classification.C` does not work. In principle both should use the Python interface to TMVA, `libPyMVA`. I would need to reproduce your condo environment. I’ll try to do it in the next days

Best,

Lorenzo
