ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Driver.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "Dump.h"
18
19#include <arser/arser.h>
20#include <foder/FileLoader.h>
21
22#include <functional>
23#include <iostream>
24#include <map>
25#include <memory>
26#include <vector>
27#include <string>
28
29int entry(int argc, char **argv)
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;
50 std::cout << arser;
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;
58 std::cout << arser;
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 // Load Circle model from a circle file
80 foder::FileLoader fileLoader{model_file};
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
Definition FileLoader.h:39
int entry(int argc, char **argv)
Definition Driver.cpp:29
void dump(const coco::Op *op, int indent)
Definition Dump.cpp:177
Definition arser.h:39