30{
32 "circle-inspect allows users to retrieve various information from a Circle model file"};
33 arser.add_argument(
"--operators").nargs(0).help(
"Dump operators in circle file");
34 arser.add_argument(
"--conv2d_weight")
35 .nargs(0)
36 .help("Dump Conv2D series weight operators in circle file");
37 arser.add_argument(
"--constants").nargs(0).help(
"Dump constant tensors name");
38 arser.add_argument(
"--op_version").nargs(0).help(
"Dump versions of the operators in circle file");
39 arser.add_argument(
"--tensor_dtype").nargs(0).help(
"Dump dtype of tensors");
40 arser.add_argument(
"--tensor_shape").nargs(0).help(
"Dump shape of tensors");
41 arser.add_argument(
"circle").help(
"Circle file to inspect");
42
43 try
44 {
45 arser.parse(argc, argv);
46 }
47 catch (const std::runtime_error &err)
48 {
49 std::cout << err.what() << std::endl;
51 return 255;
52 }
53
54 if (!
arser[
"--operators"] && !
arser[
"--conv2d_weight"] && !
arser[
"--op_version"] &&
55 !
arser[
"--tensor_dtype"] && !
arser[
"--constants"] && !
arser[
"--tensor_shape"])
56 {
57 std::cout << "At least one option must be specified" << std::endl;
59 return 255;
60 }
61
62 std::vector<std::unique_ptr<circleinspect::DumpInterface>> dumps;
63
64 if (
arser[
"--operators"])
65 dumps.push_back(std::make_unique<circleinspect::DumpOperators>());
66 if (
arser[
"--conv2d_weight"])
67 dumps.push_back(std::make_unique<circleinspect::DumpConv2DWeight>());
68 if (
arser[
"--op_version"])
69 dumps.push_back(std::make_unique<circleinspect::DumpOperatorVersion>());
70 if (
arser[
"--tensor_dtype"])
71 dumps.push_back(std::make_unique<circleinspect::DumpTensorDType>());
72 if (
arser[
"--constants"])
73 dumps.push_back(std::make_unique<circleinspect::DumpConstants>());
74 if (
arser[
"--tensor_shape"])
75 dumps.push_back(std::make_unique<circleinspect::DumpTensorShape>());
76
77 std::string model_file =
arser.get<std::string>(
"circle");
78
79
81 std::vector<char> modelData = fileLoader.
load();
82 const circle::Model *circleModel = circle::GetModel(modelData.data());
83 if (circleModel == nullptr)
84 {
85 std::cerr << "ERROR: Failed to load circle '" << model_file << "'" << std::endl;
86 return 255;
87 }
88
89 for (
auto &
dump : dumps)
90 {
91 dump->run(std::cout, circleModel, &modelData);
92 }
93
94 return 0;
95}
DataBuffer load(void) const
void dump(const coco::Op *op, int indent)