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  cout << "This is simple example with Keras neural network model loading into C++.\n"
19  << "Keras model will be used in C++ for prediction only." << endl;
20 
21  DataChunk *sample = new DataChunk2D();
22  sample->read_from_file("./example/sample_mnist.dat");
23  std::cout << sample->get_3d().size() << std::endl;
24  KerasModel m("./example/dumped.nnet");
25  m.compute_output(sample);
26 
27  return 0;
28 }
int main()
Definition: example_main.cc:17
virtual void read_from_file(const std::string &fname)
Definition: keras_model.h:50
STL namespace.
virtual std::vector< std::vector< std::vector< float > > > const & get_3d() const
Definition: keras_model.h:46
std::vector< float > compute_output(keras::DataChunk *dc)
Definition: keras_model.cc:400
QTextStream & endl(QTextStream &s)