LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
example_main.cc
Go to the documentation of this file.
1 #include "keras_model.h"
2 
3 #include <iostream>
4 
5 using namespace std;
6 using namespace keras;
7 
8 // Step 1
9 // Dump keras model and input sample into text files
10 // python dump_to_simple_cpp.py -a example/my_nn_arch.json -w example/my_nn_weights.h5 -o example/dumped.nnet
11 // Step 2
12 // Use text files in c++ example. To compile:
13 // g++ keras_model.cc example_main.cc
14 // To execute:
15 // a.out
16 
17 int main()
18 {
19  cout << "This is simple example with Keras neural network model loading into C++.\n"
20  << "Keras model will be used in C++ for prediction only." << endl;
21 
22  DataChunk* sample = new DataChunk2D();
23  sample->read_from_file("./example/sample_mnist.dat");
24  std::cout << sample->get_3d().size() << std::endl;
25  KerasModel m("./example/dumped.nnet");
26  m.compute_output(sample);
27 
28  return 0;
29 }
int main()
Definition: example_main.cc:17
virtual void read_from_file(const std::string &fname)
Definition: keras_model.h:56
STL namespace.
virtual std::vector< std::vector< std::vector< float > > > const & get_3d() const
Definition: keras_model.h:49
std::vector< float > compute_output(keras::DataChunk *dc)
Definition: keras_model.cc:421