1 #include "predictor_config.h"     5 #include "caffe2/core/init.h"     6 #include "caffe2/utils/proto_utils.h"     7 #ifdef CAFFE2_OPTIMIZER     8 #include "caffe2/opt/optimizer.h"    18 const NetDef& getNet(
const MetaNetDef& def, 
const std::string& name) {
    19   for (
const auto& n : def.nets()) {
    20     if (n.key() == name) {
    24   CAFFE_THROW(
"Net not found: ", name);
    27 const ::google::protobuf::RepeatedPtrField<::std::string>& getBlobs(
    28     const MetaNetDef& def,
    29     const std::string& name) {
    30   for (
const auto& b : def.blobs()) {
    31     if (b.key() == name) {
    35   CAFFE_THROW(
"Blob not found: ", name);
    41 makePredictorConfig(
const MetaNetDef& def, Workspace* parent, 
bool run_init) {
    42   const auto& init_net =
    43       getNet(def, PredictorConsts::default_instance().global_init_net_type());
    45       getNet(def, PredictorConsts::default_instance().predict_net_type());
    46   auto config = makePredictorConfig(init_net, run_net, parent, run_init);
    48       getBlobs(def, PredictorConsts::default_instance().inputs_blob_type());
    49   for (
const auto& input : inputs) {
    50     config.input_names.emplace_back(input);
    54       getBlobs(def, PredictorConsts::default_instance().outputs_blob_type());
    55   for (
const auto& output : outputs) {
    56     config.output_names.emplace_back(output);
    61 PredictorConfig makePredictorConfig(
    62     const NetDef& init_net,
    63     const NetDef& run_net,
    67   PredictorConfig config;
    68   config.ws = std::make_shared<Workspace>(parent);
    69   auto& ws = *config.ws;
    70   config.predict_net = std::make_shared<NetDef>(run_net);
    72     CAFFE_ENFORCE(ws.RunNetOnce(init_net));
    78       !ArgumentHelper::HasArgument(*config.predict_net, 
"disable_nomnigraph")) {
    79 #ifdef CAFFE2_OPTIMIZER    82           opt::optimize(*config.predict_net, &ws, optimization);
    83     } 
catch (
const std::exception& e) {
    84       LOG(WARNING) << 
"Optimization pass failed: " << e.what();
    87     static std::atomic<bool> warningEmitted{};
    89     if (!warningEmitted.exchange(
true)) {
    90       LOG(WARNING) << 
"Caffe2 is compiled without optimization passes.";
 A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
 
bool GlobalInit(int *pargc, char ***pargv)
Initialize the global environment of caffe2.