Caffe2 - C++ API
A deep learning, cross platform ML framework
predictor.h
1 #pragma once
2 
3 #include <unordered_set>
4 #include "caffe2/core/net.h"
5 #include "caffe2/core/tensor.h"
6 #include "caffe2/proto/metanet.pb.h"
7 #include "caffe2/proto/predictor_consts.pb.h"
8 
9 namespace caffe2 {
10 
11 class Predictor {
12  public:
13  using TensorVector = std::vector<TensorCPU*>;
14  using TensorMap = std::unordered_map<std::string, TensorCPU*>;
15 
16  // MetaNetDef contains 'init_net', 'run_net', and meta-info
17  // The meta-info is used to verify inputs are correctly passed
18  Predictor(const MetaNetDef& net, Workspace* parent = nullptr);
19 
20  // Runs the `init_net` once, then saves the `run_net` to be executed
21  // in `::run`
22  Predictor(
23  const NetDef& init_net,
24  const NetDef& run_net,
25  Workspace* parent = nullptr);
26  ~Predictor();
27 
28  // Executes `run_net` on the inputs.
29  // The first `inputs.size()` inputs from run_net::external_inputs
30  // are shared with the data in `inputs`.
31 
32  // Precondition:
33  // inputs.size() <= run_net_.external_inputs.size()
34 
35  // Postcondition:
36  // outputs->size() == run_net.external_inputs.size()
37 
38  // Returns true on success
39  bool run(const TensorVector& inputs, TensorVector* outputs);
40 
41  // Similar to run, but consumes a map of name to tensor as input
42  bool run_map(const TensorMap& inputs, TensorVector* outputs);
43 
44  const NetDef& def() const {
45  return run_net_;
46  };
47 
48  Workspace* ws() {
49  return &ws_;
50  };
51 
52  private:
53  NetDef run_net_;
54  Workspace ws_;
55  std::unordered_set<std::string> inputNames_;
56 };
57 }
Workspace is a class that holds all the related objects created during runtime: (1) all blobs...
Definition: workspace.h:47
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...