From 32ffb40f9fdaafd1e5ecae4e0542c8b5ee757034 Mon Sep 17 00:00:00 2001 From: Liangliang He Date: Thu, 26 Apr 2018 20:47:05 +0800 Subject: [PATCH] Add introspective build info --- mace/examples/example.cc | 6 ++++++ mace/python/tools/converter.py | 2 +- mace/python/tools/model.jinja2 | 13 +++++++++++++ mace/python/tools/model_header.jinja2 | 6 ++++++ mace/python/tools/source_converter_lib.py | 11 +++++++++-- mace/tools/validation/mace_run.cc | 6 ++++++ 6 files changed, 41 insertions(+), 3 deletions(-) diff --git a/mace/examples/example.cc b/mace/examples/example.cc index 52809a4f..424f06ec 100644 --- a/mace/examples/example.cc +++ b/mace/examples/example.cc @@ -47,7 +47,10 @@ extern void UnloadModelData(const unsigned char *model_data); extern NetDef CreateNet(const unsigned char *model_data); +extern const std::string ModelName(); extern const std::string ModelChecksum(); +extern const std::string ModelBuildTime(); +extern const std::string ModelBuildOptions(); } // namespace MACE_MODEL_TAG } // namespace mace @@ -246,7 +249,10 @@ int Main(int argc, char **argv) { gflags::ParseCommandLineFlags(&argc, &argv, true); LOG(INFO) << "mace version: " << MaceVersion(); + LOG(INFO) << "model name: " << mace::MACE_MODEL_TAG::ModelName(); LOG(INFO) << "model checksum: " << mace::MACE_MODEL_TAG::ModelChecksum(); + LOG(INFO) << "build time: " << mace::MACE_MODEL_TAG::ModelBuildTime(); + LOG(INFO) << "build options: " << mace::MACE_MODEL_TAG::ModelBuildOptions(); LOG(INFO) << "input node: " << FLAGS_input_node; LOG(INFO) << "input shape: " << FLAGS_input_shape; LOG(INFO) << "output node: " << FLAGS_output_node; diff --git a/mace/python/tools/converter.py b/mace/python/tools/converter.py index b14d8912..056a0b2c 100644 --- a/mace/python/tools/converter.py +++ b/mace/python/tools/converter.py @@ -84,7 +84,7 @@ def main(unused_args): source_converter_lib.convert_to_source( output_graph_def, model_checksum, FLAGS.template, FLAGS.obfuscate, FLAGS.model_tag, FLAGS.output, FLAGS.runtime, - FLAGS.embed_model_data) + FLAGS.embed_model_data, FLAGS.winograd) else: with open(FLAGS.output, "wb") as f: f.write(output_graph_def.SerializeToString()) diff --git a/mace/python/tools/model.jinja2 b/mace/python/tools/model.jinja2 index b72f84e0..3555b205 100644 --- a/mace/python/tools/model.jinja2 +++ b/mace/python/tools/model.jinja2 @@ -154,9 +154,22 @@ NetDef CreateNet(const unsigned char *model_data) { return net_def; } +const std::string ModelName() { + return {{ tag|tojson }}; +} + const std::string ModelChecksum() { return {{ model_pb_checksum|tojson }}; } +const std::string ModelBuildTime() { + return {{ build_time|tojson }}; +} + +const std::string ModelBuildOptions() { + return {{ "runtime: {}, obfuscate: {}, embed_model_data: {}, winograd: {}" + .format(runtime, obfuscate, embed_model_data, winograd_conv)|tojson }}; +} + } // namespace {{tag}} } // namespace mace diff --git a/mace/python/tools/model_header.jinja2 b/mace/python/tools/model_header.jinja2 index 8ef977db..ace89933 100644 --- a/mace/python/tools/model_header.jinja2 +++ b/mace/python/tools/model_header.jinja2 @@ -30,8 +30,14 @@ void UnloadModelData(const unsigned char *model_data); NetDef CreateNet(const unsigned char *model_data); +const std::string ModelName(); + const std::string ModelChecksum(); +const std::string ModelBuildTime(); + +const std::string ModelBuildOptions(); + } // namespace {{ tag }} } // namespace mace diff --git a/mace/python/tools/source_converter_lib.py b/mace/python/tools/source_converter_lib.py index 9d6bc897..c9fda3de 100644 --- a/mace/python/tools/source_converter_lib.py +++ b/mace/python/tools/source_converter_lib.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import datetime import os import uuid import numpy as np @@ -124,7 +125,8 @@ def stringfy(value): def convert_to_source(net_def, mode_pb_checksum, template_dir, obfuscate, - model_tag, output, runtime, embed_model_data): + model_tag, output, runtime, embed_model_data, + winograd_conv): if obfuscate: obfuscate_name(net_def) else: @@ -193,6 +195,7 @@ def convert_to_source(net_def, mode_pb_checksum, template_dir, obfuscate, counter += 1 # generate model source files + build_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') template_name = 'model.jinja2' tensors = [ TensorInfo(i, net_def.tensors[i], runtime) @@ -203,7 +206,11 @@ def convert_to_source(net_def, mode_pb_checksum, template_dir, obfuscate, net=net_def, tag=model_tag, runtime=runtime, - model_pb_checksum=mode_pb_checksum) + obfuscate=obfuscate, + embed_model_data=embed_model_data, + winograd_conv=winograd_conv, + model_pb_checksum=mode_pb_checksum, + build_time=build_time) with open(output, "wb") as f: f.write(source) diff --git a/mace/tools/validation/mace_run.cc b/mace/tools/validation/mace_run.cc index c0d98489..2a709ede 100644 --- a/mace/tools/validation/mace_run.cc +++ b/mace/tools/validation/mace_run.cc @@ -52,7 +52,10 @@ extern void UnloadModelData(const unsigned char *model_data); extern NetDef CreateNet(const unsigned char *model_data); +extern const std::string ModelName(); extern const std::string ModelChecksum(); +extern const std::string ModelBuildTime(); +extern const std::string ModelBuildOptions(); } // namespace MACE_MODEL_TAG } // namespace mace @@ -355,7 +358,10 @@ int Main(int argc, char **argv) { gflags::ParseCommandLineFlags(&argc, &argv, true); LOG(INFO) << "mace version: " << MaceVersion(); + LOG(INFO) << "model name: " << mace::MACE_MODEL_TAG::ModelName(); LOG(INFO) << "model checksum: " << mace::MACE_MODEL_TAG::ModelChecksum(); + LOG(INFO) << "build time: " << mace::MACE_MODEL_TAG::ModelBuildTime(); + LOG(INFO) << "build options: " << mace::MACE_MODEL_TAG::ModelBuildOptions(); LOG(INFO) << "input node: " << FLAGS_input_node; LOG(INFO) << "input shape: " << FLAGS_input_shape; LOG(INFO) << "output node: " << FLAGS_output_node; -- GitLab