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

**URL:** <https://root-forum.cern.ch/t/bookmva-fatal-error-unable-to-open-input-weight-file/50442>\
**Category:** TMVA\
**Tags:** tmva\
**Created:** [June 16, 2022, 6:38pm UTC](https://root-forum.cern.ch/t/bookmva-fatal-error-unable-to-open-input-weight-file/50442 "2022-06-16T18:38:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![conrado99](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/conrado99/32/30032_2.png) [@conrado99](https://root-forum.cern.ch/u/conrado99)\
**Post date:** [June 16, 2022, 6:38pm UTC](https://root-forum.cern.ch/t/bookmva-fatal-error-unable-to-open-input-weight-file/50442/1 "2022-06-16T18:38:19Z")

</div>

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

---

<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:** [June 16, 2022, 8:26pm UTC](https://root-forum.cern.ch/t/bookmva-fatal-error-unable-to-open-input-weight-file/50442/2 "2022-06-16T20:26:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![conrado99](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/conrado99/32/30032_2.png) [@conrado99](https://root-forum.cern.ch/u/conrado99)\
**Post date:** [June 16, 2022, 9:29pm UTC](https://root-forum.cern.ch/t/bookmva-fatal-error-unable-to-open-input-weight-file/50442/3 "2022-06-16T21:29:32Z")

</div>

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.

---

<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:** [June 17, 2022, 2:46pm UTC](https://root-forum.cern.ch/t/bookmva-fatal-error-unable-to-open-input-weight-file/50442/4 "2022-06-17T14:46:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![conrado99](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/conrado99/32/30032_2.png) [@conrado99](https://root-forum.cern.ch/u/conrado99)\
**Post date:** [June 17, 2022, 5:06pm UTC](https://root-forum.cern.ch/t/bookmva-fatal-error-unable-to-open-input-weight-file/50442/5 "2022-06-17T17:06:55Z")

</div>

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.

---

<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:** [June 17, 2022, 5:59pm UTC](https://root-forum.cern.ch/t/bookmva-fatal-error-unable-to-open-input-weight-file/50442/6 "2022-06-17T17:59:21Z")

</div>

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
