<BookMVA> fatal error: unable to open input weight file

Hi,
i’ve trained a dnn_cpu with TMVAClassification.C tutorial. But when i try to read the weights.xlm file on my c++ program to use the trained network, i obtain the following error:
<FATAL> : <BookMVA> fatal error: unable to open input weight file: weights/DNN/W/TMVAClassification_DNN_CPU.weights.xml ***> abort program execution terminate called after throwing an instance of 'std::runtime_error' what(): FATAL error

To read the weights file i use a reader, as follow:
TMVA::Reader *readerW = new TMVA::Reader("!Color:!Silent"); readerW->AddVariable ( "DeltaR", &AddPairJetsVariables[0] ); readerW->AddVariable ( "DeltapT", &AddPairJetsVariables[1] ); readerW->AddVariable ( "DeltaPhi", &AddPairJetsVariables[2] ); readerW->AddVariable ( "DeltaEta", &AddPairJetsVariables[3] ); readerW->AddVariable ( "SumCSV", &AddPairJetsVariables[4] ); readerW->AddVariable ( "InvMass", &AddPairJetsVariables[5] ); readerW->BookMVA("DNN_CPU", Weightsfdir+WeightsfnameW);

And in order to obtain the response, i use:
WDNNResponseSgn = readerW->EvaluateMVA("DNN_CPU");

I’ve done the same with a BDT method only changing DNN_CPU for BDT and it worked.

Thanks for the help

Hi,
This is strange, can you please share the weight files and the Reader code, so I can try to reproduce this problem,

Cheers

Lorenzo

Thanks for your help. I’m doing my final master project and this is my b plan after having trained a network with PyKeras and not being able to read the weights with this c++ reader.

I’ve tried to upload a zip folder but i’m a new user and i can’t post links.
https://drive.google.com/file/d/1bagb7y761FOW1kdqJEz4qyYEezo4bG3B/view?usp=sharing

I don’t know if you need the input file too. It’s heavy.

Hi,

Thank you for sharing the file. The error you get is because the file path of the weights is wrong.
in your program you have defined it as
weights/DNN/W/TMVAClassification_DNN_CPU.weights.xml

instead the correct path for the weight file seems to be:

weights/BDT/W/TMVAClassification_DNN_CPU.weights.xml

Cheers

Lorenzo

Thanks. I had used the program for BDT before and changed all the BDTs to DNN with the text editor, but the weight files were in the same folder as the BDT.

Do you know if this can be done with pykeras weight files?

I train in python and the files have the same weight.xlm extension. I don’t know if they can be used in c++ in a similar way. When I tried it didn’t even compile.

Hi,
You can use the weight file obtained with Keras in a similar way, but the reader will be quite inefficient.
The weight file obtained for pokers requires also another file, the original trained model which is saved from keras (a *.h5 file).

Lorenzo