Caffe2 - C++ API
A deep learning, cross platform ML framework
predictor.h
1 
17 #pragma once
18 
19 #include <unordered_set>
20 #include "caffe2/core/net.h"
21 #include "caffe2/core/tensor.h"
22 #include "caffe2/proto/metanet.pb.h"
23 #include "caffe2/proto/predictor_consts.pb.h"
24 
25 namespace caffe2 {
26 
27 class Predictor {
28  public:
29  using TensorVector = std::vector<TensorCPU*>;
30  using TensorMap = std::unordered_map<std::string, TensorCPU*>;
31 
32  // MetaNetDef contains 'init_net', 'run_net', and meta-info
33  // The meta-info is used to verify inputs are correctly passed
34  Predictor(const MetaNetDef& net, Workspace* parent = nullptr);
35 
36  // Runs the `init_net` once, then saves the `run_net` to be executed
37  // in `::run`
38  Predictor(
39  const NetDef& init_net,
40  const NetDef& run_net,
41  Workspace* parent = nullptr);
42  ~Predictor();
43 
44  // Executes `run_net` on the inputs.
45  // The first `inputs.size()` inputs from run_net::external_inputs
46  // are shared with the data in `inputs`.
47 
48  // Precondition:
49  // inputs.size() <= run_net_.external_inputs.size()
50 
51  // Postcondition:
52  // outputs->size() == run_net.external_inputs.size()
53 
54  // Returns true on success
55  bool run(const TensorVector& inputs, TensorVector* outputs);
56 
57  // Similar to run, but consumes a map of name to tensor as input
58  bool run_map(const TensorMap& inputs, TensorVector* outputs);
59 
60  const NetDef& def() const {
61  return run_net_;
62  };
63 
64  Workspace* ws() {
65  return &ws_;
66  };
67 
68  private:
69  NetDef run_net_;
70  Workspace ws_;
71  std::unordered_set<std::string> inputNames_;
72 };
73 }
Workspace is a class that holds all the related objects created during runtime: (1) all blobs...
Definition: workspace.h:63
Copyright (c) 2016-present, Facebook, Inc.