73 ctx->
sinks()->
append(std::make_unique<hermes::ConsoleReporter>());
74 ctx->
config(std::make_unique<EnvConfig>(
"TF2NNPKG_Log"));
83 std::cerr <<
"Usage:" << std::endl;
84 std::cerr <<
" tf2nnpkg --info <path/to/info>" << std::endl;
85 std::cerr <<
" --graphdef <path/to/pb>" << std::endl;
86 std::cerr <<
" -o <path/to/package/dir>" << std::endl;
92 ::Logger name { ::LoggingContext::get() }
94#define INFO(name) HERMES_INFO(name)
99void internal_error(
void)
101 std::cerr <<
"tf2nnpkg: internal compiler error" << std::endl;
111std::string extract_modelname(std::string tf_path)
115 const std::string key =
".pb";
116 auto suffix_index = filename.find(key);
117 assert(suffix_index != std::string::npos);
118 assert(suffix_index + key.size() == filename.size());
120 return filename.substr(0, suffix_index);
132 int operator()(
int argc,
char **argv)
const;
135EntryFunctor::EntryFunctor()
140EntryFunctor::~EntryFunctor()
145int EntryFunctor::operator()(
int argc,
char **argv)
const
157 std::map<std::string, std::function<void(
const std::string &arg)>> argparse;
159 std::string arg_info;
160 std::string arg_graphdef;
161 std::string arg_output;
163 argparse[
"--info"] = [&](
const std::string &
arg) { arg_info =
arg; };
164 argparse[
"--graphdef"] = [&](
const std::string &
arg) { arg_graphdef =
arg; };
165 argparse[
"-o"] = [&](
const std::string &
arg) { arg_output =
arg; };
169 for (
int n = 1; n <
argc; n += 2)
171 const std::string tag{
argv[n]};
172 const std::string
arg{
argv[n + 1]};
174 auto it = argparse.find(tag);
175 if (it == argparse.end())
177 std::cerr <<
"Option '" << tag <<
"' is not supported" << std::endl;
184 if (arg_info.empty() || arg_graphdef.empty() || arg_output.empty())
191 std::string info_path = arg_info;
192 std::string tf_path = arg_graphdef;
195 std::string outdir_path = arg_output;
198 std::string model_filename = modelname +
".circle";
203 std::cout <<
"Read '" << info_path <<
"'" << std::endl;
207 for (
const auto &
info :
nnkit::support::tftestinfo::
parse(info_path.c_str()))
209 switch (
info->kind())
222 throw std::runtime_error{
"Unknown kind"};
227 std::cout <<
"Read '" << info_path <<
"' - Done" << std::endl;
229 std::cout <<
"Import from '" << tf_path <<
"'" << std::endl;
230 auto g =
import(sig, tf_path);
231 std::cout <<
"Import from '" << tf_path <<
"' - Done" << std::endl;
233 INFO(l) <<
"Import Graph" << std::endl;
234 INFO(l) << locop::fmt<locop::Formatter::LinearV1>(g) << std::endl;
238 std::cout <<
"Make output directory '" << outdir_path <<
"'" << std::endl;
240 throw std::runtime_error(
"Fail to make directory " + outdir_path);
241 std::cout <<
"Make output directory '" << outdir_path <<
"' - Done" << std::endl;
246 std::cout <<
"Make package directory '" << nnpkg_path <<
"'" << std::endl;
248 throw std::runtime_error(
"Fail to make directory " + nnpkg_path);
249 std::cout <<
"Make package directory '" << nnpkg_path <<
"' - Done" << std::endl;
252 std::cout <<
"Export into '" << circle_path <<
"'" << std::endl;
254 std::cout <<
"Export into '" << circle_path <<
"' - Done" << std::endl;
258 std::cout <<
"Make metadata directory '" << metadata_path <<
"'" << std::endl;
260 throw std::runtime_error(
"Fail to make directory " + metadata_path);
261 std::cout <<
"Make metadata directory '" << metadata_path <<
"' - Done" << std::endl;
264 std::cout <<
"Make manifest file '" << manifest_path <<
"'" << std::endl;
265 std::ofstream manifest_file;
266 manifest_file.open(manifest_path, std::ios::out | std::ios::binary);
267 manifest_file <<
"{\n";
268 manifest_file <<
" \"major-version\" : \"1\",\n";
269 manifest_file <<
" \"minor-version\" : \"0\",\n";
270 manifest_file <<
" \"patch-version\" : \"0\",\n";
271 manifest_file <<
" \"models\" : [ \"" + model_filename +
"\" ],\n";
272 manifest_file <<
" \"model-types\" : [ \"circle\" ]\n";
273 manifest_file <<
"}";
274 manifest_file.close();
275 std::cout <<
"Make manifest file '" << manifest_path <<
"' - Done" << std::endl;
289 return entry(argc, argv);
This file contains functions to parse test.info files in moco/test/tf.
void dumpToFile(const char *path) const
write to a file
Source::Registry * sources(void)
Sink::Registry * sinks(void)
const Config * config(void) const
Get the global configuration.
void activate(Registry *, MessageBus *)
std::unique_ptr< loco::Graph > load(const ModelSignature &, const char *, FileType) const
int entry(const int argc, char **argv)
volatile const char info[]
KnobTrait< K >::ValueType get(void)
bool mkdir(const std::string &path)
bool is_dir(const std::string &path)
std::string join(const std::string &path1, const std::string &path2)
std::string normalize_path(const std::string &path)
Normalize compatible separator in path to default separator.
std::string basename(const std::string &path)
std::vector< std::unique_ptr< ParsedTensor > > parse(const char *info_path)
Function to parse test.info.
static hermes::Context * get(void)
virtual void append(std::unique_ptr< Sink > &&)=0
static hermes::Context * get(void)
Class to store information to run a model. Normally this info comes from users via CLI params or conf...
void add_input(const TensorName &input)
void add_output(const TensorName &output)
void shape(const std::string &node_name, const angkor::TensorShape &shape)
Adds node name and its shape provided from user.
const std::string & name() const