# How to set ResNet50 structure with cnn of TMVA

**URL:** <https://root-forum.cern.ch/t/how-to-set-resnet50-structure-with-cnn-of-tmva/34748>\
**Category:** TMVA\
**Created:** [June 21, 2019, 2:51pm UTC](https://root-forum.cern.ch/t/how-to-set-resnet50-structure-with-cnn-of-tmva/34748 "2019-06-21T14:51:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![siguang](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/41988e/32.png) [@siguang](https://root-forum.cern.ch/u/siguang)\
**Post date:** [June 21, 2019, 2:51pm UTC](https://root-forum.cern.ch/t/how-to-set-resnet50-structure-with-cnn-of-tmva/34748/1 "2019-06-21T14:51:29Z")

</div>

Structure of ResNet50 or ResNet152 is so powerful than the flat cnn, can someone give an example to use TMVA or other root code (better with c++) to set up the same cnn structure as ResNet? Thanks in advance!

Best Regards  
siguang

---

<div class="post-metadata">

**Author:** ![Axel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/axel/32/11084_2.png) [@Axel](https://root-forum.cern.ch/u/Axel)\
**Post date:** [June 21, 2019, 2:52pm UTC](https://root-forum.cern.ch/t/how-to-set-resnet50-structure-with-cnn-of-tmva/34748/2 "2019-06-21T14:52:48Z")

</div>

@sitong @moneta can you help maybe?

---

<div class="post-metadata">

**Author:** ![kialbert](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/kialbert/32/16537_2.png) [@kialbert](https://root-forum.cern.ch/u/kialbert)\
**Post date:** [June 24, 2019, 3:58pm UTC](https://root-forum.cern.ch/t/how-to-set-resnet50-structure-with-cnn-of-tmva/34748/3 "2019-06-24T15:58:09Z")

</div>

Hi,

The way this is currently supported in TMVA is through the generic keras interface. This means you have to set up you model with keras, save it to disk and load it through the TMVA `PyKeras` methods.

_Please note that any problems you might encouter with external applications or code such as keras, tensorflow, and the linked git repositories and gists are unfortunately not covered in this forum._

A sketch in python, provided for reference, follows below. Adaption to c++ should be straightforward. You would still need to generate the keras model through python.

```auto
# Create directory structure
mkdir tmvaresnet
cd tmvaresnet

# Get stuff
wget https://gist.githubusercontent.com/ashlaban/6be0ddc58d940d6ab1783ac0dbab19cc/raw/d5e8d6d8a0c7be8a2dab78f4582e450b2c20a1b7/resnet.py
wget https://gist.githubusercontent.com/ashlaban/142827263a51488c3098da0e456a197a/raw/0c21228cb1ee29ad4402bb4c674cfebe3872a5a1/train.py
git clone https://github.com/stwunsch/tmva_mnist.git

# Run training
python tmva_mnist/create_dataset.py
python train.py

```

This is tested on my local machine with a _recent_ check out from the development version. Your mileage might vary 🙂

Note: I did not inspect the output of this script since it takes ages to run on my laptop. It _seems_ to work as it is training and converging.

Links to the gists in clickable form:

- [resnet.py](https://gist.github.com/ashlaban/6be0ddc58d940d6ab1783ac0dbab19cc)
- [train.py](https://gist.github.com/ashlaban/142827263a51488c3098da0e456a197a)

Cheers,  
Kim
