Caffe2 - C++ API
A deep learning, cross platform ML framework
print_registered_core_operators.cc
1 
17 #include <iostream>
18 #include <string>
19 
20 #include "caffe2/core/init.h"
21 #include "caffe2/core/operator.h"
22 #include "caffe2/core/operator_schema.h"
23 
24 CAFFE2_DEFINE_string(schema, "",
25  "Print doc and schema of a particular operator");
26 
27 static bool HasSchema(const std::string& str) {
28  return caffe2::OpSchemaRegistry::Schema(str);
29 }
30 
31 static bool HasDoc(const std::string& str) {
32  const auto* schema = caffe2::OpSchemaRegistry::Schema(str);
33  return (schema != nullptr) && (schema->doc() != nullptr);
34 }
35 
36 int main(int argc, char** argv) {
37  caffe2::GlobalInit(&argc, &argv);
38 
39  if (!caffe2::FLAGS_schema.empty()) {
40  const auto* schema = caffe2::OpSchemaRegistry::Schema(
41  caffe2::FLAGS_schema);
42  if (!schema) {
43  std::cerr << "Operator " << caffe2::FLAGS_schema
44  << " doesn't have a schema" << std::endl;
45  return 1;
46  }
47  std::cout << "Operator " << caffe2::FLAGS_schema << ": " << std::endl
48  << *schema;
49  return 0;
50  }
51 
52  for (const auto& pair : *caffe2::gDeviceTypeRegistry()) {
53  std::cout << "Device type " << pair.first
54 #ifndef CAFFE2_USE_LITE_PROTO
55  << " (" << caffe2::DeviceType_Name(
56  static_cast<caffe2::DeviceType>(pair.first))
57  << ")"
58 #endif
59  << std::endl;
60  for (const auto& key : pair.second->Keys()) {
61  std::cout << "\t(schema: " << HasSchema(key) << ", doc: " << HasDoc(key)
62  << ")\t" << key << std::endl;
63  }
64  }
65 
66  std::cout << "Operators that have gradients registered:" << std::endl;
67  for (const auto& key : caffe2::GradientRegistry()->Keys()) {
68  std::cout << "\t(schema: " << HasSchema(key) << ", doc: "
69  << HasDoc(key) << ")\t"
70  << key << std::endl;
71  }
72  return 0;
73 }
bool GlobalInit(int *pargc, char ***pargv)
Initialize the global environment of caffe2.
Definition: init.cc:18