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

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:

/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:

but no solutions to the problem were reported.

This is my code:
validationClass.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

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

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)

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

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

[2] (corrected by me)

...
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.

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, which is a standalone inference engine for Keras models.

Another solution is using the Python/C API to call keras from C++. This is a simple full example of such a solution.

Cheers
Stefan