# Standalone C++ response classes for pyKeras does not work. Class presents a series of typos

**URL:** <https://root-forum.cern.ch/t/standalone-c-response-classes-for-pykeras-does-not-work-class-presents-a-series-of-typos/29110>\
**Category:** TMVA\
**Created:** [May 23, 2018, 1:47pm UTC](https://root-forum.cern.ch/t/standalone-c-response-classes-for-pykeras-does-not-work-class-presents-a-series-of-typos/29110 "2018-05-23T13:47:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![a.bragagnolo](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/f14d63/32.png) [@a.bragagnolo](https://root-forum.cern.ch/u/a.bragagnolo)\
**Post date:** [May 23, 2018, 1:47pm UTC](https://root-forum.cern.ch/t/standalone-c-response-classes-for-pykeras-does-not-work-class-presents-a-series-of-typos/29110/1 "2018-05-23T13:47:25Z")

</div>

Hi TMVA experts,

I want to use TMVA as an interface for Keras. I have no problems in the training, but since my method needs to be deployed in a system where I do not control the root release (i.e. in a system with no tensorflow and keras available) I want to use the standalone c++ class option.

The problem is that the above-mentioned class simply does not work. When I try to use it I get these error:

```auto
/home/alberto/Desktop/training/dataset/weights/TMVAClassification_DNN_Barrel.class.C:291:34: error: extra qualification on member 'GetMvaValue'
   inline double ReadDNN_Barrel::GetMvaValue( const std::vector<double>& inputValues ) const
                 ~~~~~~~~~~~~~~~~ ^
/home/alberto/Desktop/training/dataset/weights/TMVAClassification_DNN_Barrel.class.C:291:34: error: class member cannot be redeclared
/home/alberto/Desktop/training/dataset/weights/TMVAClassification_DNN_Barrel.class.C:235:11: note: previous declaration is here
   double GetMvaValue( const std::vector<double>& inputValues ) const;
          ^
/home/alberto/Desktop/training/dataset/weights/TMVAClassification_DNN_Barrel.class.C:331:29: error: extra qualification on member 'InitTransform_1'
inline void ReadDNN_Barrel::InitTransform_1()
            ~~~~~~~~~~~~~~~~ ^
/home/alberto/Desktop/training/dataset/weights/TMVAClassification_DNN_Barrel.class.C:331:29: error: class member cannot be redeclared
/home/alberto/Desktop/training/dataset/weights/TMVAClassification_DNN_Barrel.class.C:257:9: note: previous declaration is here
   void InitTransform_1();
        ^
/home/alberto/Desktop/training/dataset/weights/TMVAClassification_DNN_Barrel.class.C:487:29: error: extra qualification on member 'Transform_1'
inline void ReadDNN_Barrel::Transform_1( std::vector<double>& iv, int cls) const
            ~~~~~~~~~~~~~~~~ ^
/home/alberto/Desktop/training/dataset/weights/TMVAClassification_DNN_Barrel.class.C:487:29: error: class member cannot be redeclared
/home/alberto/Desktop/training/dataset/weights/TMVAClassification_DNN_Barrel.class.C:258:9: note: previous declaration is here
   void Transform_1( std::vector<double> & iv, int sigOrBgd ) const;
        ^
/home/alberto/Desktop/training/dataset/weights/TMVAClassification_DNN_Barrel.class.C:572:29: error: extra qualification on member 'InitTransform_2'
inline void ReadDNN_Barrel::InitTransform_2()
            ~~~~~~~~~~~~~~~~ ^
/home/alberto/Desktop/training/dataset/weights/TMVAClassification_DNN_Barrel.class.C:572:29: error: class member cannot be redeclared
/home/alberto/Desktop/training/dataset/weights/TMVAClassification_DNN_Barrel.class.C:259:9: note: previous declaration is here
   void InitTransform_2();
        ^
/home/alberto/Desktop/training/dataset/weights/TMVAClassification_DNN_Barrel.class.C:196772:29: error: extra qualification on member 'Transform_2'
inline void ReadDNN_Barrel::Transform_2( std::vector<double>& iv, int clsIn) const
            ~~~~~~~~~~~~~~~~ ^
/home/alberto/Desktop/training/dataset/weights/TMVAClassification_DNN_Barrel.class.C:196772:29: error: class member cannot be redeclared
/home/alberto/Desktop/training/dataset/weights/TMVAClassification_DNN_Barrel.class.C:260:9: note: previous declaration is here
   void Transform_2( std::vector<double> & iv, int sigOrBgd ) const;
        ^
/home/alberto/Desktop/training/dataset/weights/TMVAClassification_DNN_Barrel.class.C:196879:29: error: extra qualification on member 'InitTransform_3'
inline void ReadDNN_Barrel::InitTransform_3()
            ~~~~~~~~~~~~~~~~ ^
/home/alberto/Desktop/training/dataset/weights/TMVAClassification_DNN_Barrel.class.C:196879:29: error: class member cannot be redeclared
/home/alberto/Desktop/training/dataset/weights/TMVAClassification_DNN_Barrel.class.C:261:9: note: previous declaration is here
   void InitTransform_3();
        ^
/home/alberto/Desktop/training/dataset/weights/TMVAClassification_DNN_Barrel.class.C:197035:29: error: extra qualification on member 'Transform_3'
inline void ReadDNN_Barrel::Transform_3( std::vector<double>& iv, int cls) const
            ~~~~~~~~~~~~~~~~ ^
/home/alberto/Desktop/training/dataset/weights/TMVAClassification_DNN_Barrel.class.C:197035:29: error: class member cannot be redeclared
/home/alberto/Desktop/training/dataset/weights/TMVAClassification_DNN_Barrel.class.C:262:9: note: previous declaration is here
   void Transform_3( std::vector<double> & iv, int sigOrBgd ) const;
        ^
/home/alberto/Desktop/training/dataset/weights/TMVAClassification_DNN_Barrel.class.C:197118:29: error: extra qualification on member 'InitTransform'
inline void ReadDNN_Barrel::InitTransform()
            ~~~~~~~~~~~~~~~~ ^
/home/alberto/Desktop/training/dataset/weights/TMVAClassification_DNN_Barrel.class.C:197118:29: error: class member cannot be redeclared
/home/alberto/Desktop/training/dataset/weights/TMVAClassification_DNN_Barrel.class.C:263:9: note: previous declaration is here
   void InitTransform();
        ^
/home/alberto/Desktop/training/dataset/weights/TMVAClassification_DNN_Barrel.class.C:197126:29: error: extra qualification on member 'Transform'
inline void ReadDNN_Barrel::Transform( std::vector<double>& iv, int sigOrBgd ) const
            ~~~~~~~~~~~~~~~~ ^
/home/alberto/Desktop/training/dataset/weights/TMVAClassification_DNN_Barrel.class.C:197126:29: error: class member cannot be redeclared
/home/alberto/Desktop/training/dataset/weights/TMVAClassification_DNN_Barrel.class.C:264:9: note: previous declaration is here
   void Transform( std::vector<double> & iv, int sigOrBgd ) const;
        ^
In file included from input_line_10:1:
/home/alberto/Desktop/training/validationClass.C:17:7: error: member 'ReadDNN_Barrel' has the same name as its class
class ReadDNN_Barrel;
      ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]

```

I have already read this topic:

> [@TMVA generated class does not compile, and unable to read xml file when using Keras interface](https://root-forum.cern.ch/t/tmva-generated-class-does-not-compile-and-unable-to-read-xml-file-when-using-keras-interface/28457):
>
> Dear experts, I trained a neural network using the TMVA interface to Keras, closely following the example given on: [https://root.cern.ch/doc/v608/ClassificationKeras\_8py\_source.html](https://root.cern.ch/doc/v608/ClassificationKeras_8py_source.html) The training and evaluation of the method work fine, but I am experiencing problems when trying to use the method in later analysis. The first issues arise when trying to set up an MVA reader as follows: reader-\>BookMVA("kerasDNN\_newVars method", "leptonMvaTraining/dataset/weights/TMVAClassification\_kerasDNN\_newV…

but no solutions to the problem were reported.

This is my code:  
[validationClass.C](https://root-forum.cern.ch/uploads/default/original/3X/c/0/c0f4459c170329da42d6e7cf923ee2f6a672da38.C) (8.2 KB)

The class is pretty big so I have uploaded it on dropbox:  
[https://www.dropbox.com/s/df1dt777sm1lied/TMVAClassification\_DNN\_Barrel.class.C?dl=0](https://www.dropbox.com/s/df1dt777sm1lied/TMVAClassification_DNN_Barrel.class.C?dl=0)

Do you have any idea how to solve this problem? (or to make the method work with the Reader in a system with no keras and tensorflow)

Thank you,  
Alberto

---

<div class="post-metadata">

**Author:** ![a.bragagnolo](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/f14d63/32.png) [@a.bragagnolo](https://root-forum.cern.ch/u/a.bragagnolo)\
**Post date:** [May 23, 2018, 2:25pm UTC](https://root-forum.cern.ch/t/standalone-c-response-classes-for-pykeras-does-not-work-class-presents-a-series-of-typos/29110/2 "2018-05-23T14:25:52Z")

</div>

**UPDATE:**

After looking more deeply into the error log I found out that the standalone class is built with lot of typos.

The class definition[1] does not have the closing bracket and following semicolon. With the [2] correction nearly the compilation errors disappears.

[1] (as built by TMVA)

```auto
...
class ReadDNN_Barrel : public IClassifierReader{
//stuff

inline double ReadDNN_Barrel::GetMvaValue( const std::vector<double>& inputValues ) const
{
//stuff
}
...

```

[2] (corrected by me)

```auto
...
class ReadDNN_Barrel : public IClassifierReader{
//stuff
}; //<-------------------------

inline double ReadDNN_Barrel::GetMvaValue( const std::vector<double>& inputValues ) const
{ //stuff }
...

```

This typo is **not** present in the standalone class for a BDT I trained simultaneusly with the pyKeras method.

I hope this post can help the developer to fix this bug.

**UPDATE 2**

Sadly even fixing the typo does not allow to use the standalone class since the definitions of the functions  
`Initialize()`  
`GetMvaValue__(std::vector<double, std::allocator<double> > const&) const`  
`Clear()`  
are completely missing.

---

<div class="post-metadata">

**Author:** ![swunsch](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/50afbb/32.png) [@swunsch](https://root-forum.cern.ch/u/swunsch)\
**Post date:** [May 27, 2018, 5:36am UTC](https://root-forum.cern.ch/t/standalone-c-response-classes-for-pykeras-does-not-work-class-presents-a-series-of-typos/29110/3 "2018-05-27T05:36:56Z")

</div>

Hi!

The reason for your problem is that the standalone c++ class option for the PyKeras method is not implemented. So unfortunately there is no immediate solution for this!

A possible solution could be the [lwtnn library](https://github.com/lwtnn/lwtnn), which is a standalone inference engine for Keras models.

Another solution is using the Python/C API to call keras from C++. [This](https://github.com/stwunsch/root_lwtnn/blob/master/test/test_pythonc.cxx) is a simple full example of such a solution.

Cheers  
Stefan
