Caffe2 - C++ API
A deep learning, cross platform ML framework
predictor_verifier.cc
1 
17 #include "caffe2/core/flags.h"
18 #include "caffe2/core/init.h"
19 #include "caffe2/predictor/predictor.h"
20 #include "caffe2/utils/proto_utils.h"
21 
22 C10_DEFINE_string(init_net, "", "The given path to the init protobuffer.");
23 C10_DEFINE_string(
24  predict_net,
25  "",
26  "The given path to the predict protobuffer.");
27 
28 namespace caffe2 {
29 
30 void run() {
31  if (FLAGS_init_net.empty()) {
32  LOG(FATAL) << "No init net specified. Use --init_net=/path/to/net.";
33  }
34  if (FLAGS_predict_net.empty()) {
35  LOG(FATAL) << "No predict net specified. Use --predict_net=/path/to/net.";
36  }
37  caffe2::NetDef init_net, predict_net;
38  CAFFE_ENFORCE(ReadProtoFromFile(FLAGS_init_net, &init_net));
39  CAFFE_ENFORCE(ReadProtoFromFile(FLAGS_predict_net, &predict_net));
40  // Can be large due to constant fills
41  VLOG(1) << "Init net: " << ProtoDebugString(init_net);
42  LOG(INFO) << "Predict net: " << ProtoDebugString(predict_net);
43  auto predictor = caffe2::make_unique<Predictor>(init_net, predict_net);
44  LOG(INFO) << "Checking that a null forward-pass works";
45  Predictor::TensorList inputVec, outputVec;
46  (*predictor)(inputVec, &outputVec);
47  CAFFE_ENFORCE_GT(outputVec.size(), 0);
48 }
49 }
50 
51 int main(int argc, char** argv) {
52  caffe2::GlobalInit(&argc, &argv);
53  caffe2::run();
54  // This is to allow us to use memory leak checks.
55  caffe2::ShutdownProtobufLibrary();
56  return 0;
57 }
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
Definition: blob.h:13
bool GlobalInit(int *pargc, char ***pargv)
Initialize the global environment of caffe2.
Definition: init.cc:44