提交 1a86f7b8 编写于 作者: 吴承辉

Merge branch 'add_build_info' into 'master'

Add introspective build info

See merge request !429
...@@ -47,7 +47,10 @@ extern void UnloadModelData(const unsigned char *model_data); ...@@ -47,7 +47,10 @@ extern void UnloadModelData(const unsigned char *model_data);
extern NetDef CreateNet(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 ModelChecksum();
extern const std::string ModelBuildTime();
extern const std::string ModelBuildOptions();
} // namespace MACE_MODEL_TAG } // namespace MACE_MODEL_TAG
} // namespace mace } // namespace mace
...@@ -246,7 +249,10 @@ int Main(int argc, char **argv) { ...@@ -246,7 +249,10 @@ int Main(int argc, char **argv) {
gflags::ParseCommandLineFlags(&argc, &argv, true); gflags::ParseCommandLineFlags(&argc, &argv, true);
LOG(INFO) << "mace version: " << MaceVersion(); 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) << "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 node: " << FLAGS_input_node;
LOG(INFO) << "input shape: " << FLAGS_input_shape; LOG(INFO) << "input shape: " << FLAGS_input_shape;
LOG(INFO) << "output node: " << FLAGS_output_node; LOG(INFO) << "output node: " << FLAGS_output_node;
......
...@@ -84,7 +84,7 @@ def main(unused_args): ...@@ -84,7 +84,7 @@ def main(unused_args):
source_converter_lib.convert_to_source( source_converter_lib.convert_to_source(
output_graph_def, model_checksum, FLAGS.template, FLAGS.obfuscate, output_graph_def, model_checksum, FLAGS.template, FLAGS.obfuscate,
FLAGS.model_tag, FLAGS.output, FLAGS.runtime, FLAGS.model_tag, FLAGS.output, FLAGS.runtime,
FLAGS.embed_model_data) FLAGS.embed_model_data, FLAGS.winograd)
else: else:
with open(FLAGS.output, "wb") as f: with open(FLAGS.output, "wb") as f:
f.write(output_graph_def.SerializeToString()) f.write(output_graph_def.SerializeToString())
......
...@@ -154,9 +154,22 @@ NetDef CreateNet(const unsigned char *model_data) { ...@@ -154,9 +154,22 @@ NetDef CreateNet(const unsigned char *model_data) {
return net_def; return net_def;
} }
const std::string ModelName() {
return {{ tag|tojson }};
}
const std::string ModelChecksum() { const std::string ModelChecksum() {
return {{ model_pb_checksum|tojson }}; 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 {{tag}}
} // namespace mace } // namespace mace
...@@ -30,8 +30,14 @@ void UnloadModelData(const unsigned char *model_data); ...@@ -30,8 +30,14 @@ void UnloadModelData(const unsigned char *model_data);
NetDef CreateNet(const unsigned char *model_data); NetDef CreateNet(const unsigned char *model_data);
const std::string ModelName();
const std::string ModelChecksum(); const std::string ModelChecksum();
const std::string ModelBuildTime();
const std::string ModelBuildOptions();
} // namespace {{ tag }} } // namespace {{ tag }}
} // namespace mace } // namespace mace
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import datetime
import os import os
import uuid import uuid
import numpy as np import numpy as np
...@@ -124,7 +125,8 @@ def stringfy(value): ...@@ -124,7 +125,8 @@ def stringfy(value):
def convert_to_source(net_def, mode_pb_checksum, template_dir, obfuscate, 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: if obfuscate:
obfuscate_name(net_def) obfuscate_name(net_def)
else: else:
...@@ -193,6 +195,7 @@ def convert_to_source(net_def, mode_pb_checksum, template_dir, obfuscate, ...@@ -193,6 +195,7 @@ def convert_to_source(net_def, mode_pb_checksum, template_dir, obfuscate,
counter += 1 counter += 1
# generate model source files # generate model source files
build_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
template_name = 'model.jinja2' template_name = 'model.jinja2'
tensors = [ tensors = [
TensorInfo(i, net_def.tensors[i], runtime) TensorInfo(i, net_def.tensors[i], runtime)
...@@ -203,7 +206,11 @@ def convert_to_source(net_def, mode_pb_checksum, template_dir, obfuscate, ...@@ -203,7 +206,11 @@ def convert_to_source(net_def, mode_pb_checksum, template_dir, obfuscate,
net=net_def, net=net_def,
tag=model_tag, tag=model_tag,
runtime=runtime, 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: with open(output, "wb") as f:
f.write(source) f.write(source)
......
...@@ -52,7 +52,10 @@ extern void UnloadModelData(const unsigned char *model_data); ...@@ -52,7 +52,10 @@ extern void UnloadModelData(const unsigned char *model_data);
extern NetDef CreateNet(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 ModelChecksum();
extern const std::string ModelBuildTime();
extern const std::string ModelBuildOptions();
} // namespace MACE_MODEL_TAG } // namespace MACE_MODEL_TAG
} // namespace mace } // namespace mace
...@@ -355,7 +358,10 @@ int Main(int argc, char **argv) { ...@@ -355,7 +358,10 @@ int Main(int argc, char **argv) {
gflags::ParseCommandLineFlags(&argc, &argv, true); gflags::ParseCommandLineFlags(&argc, &argv, true);
LOG(INFO) << "mace version: " << MaceVersion(); 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) << "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 node: " << FLAGS_input_node;
LOG(INFO) << "input shape: " << FLAGS_input_shape; LOG(INFO) << "input shape: " << FLAGS_input_shape;
LOG(INFO) << "output node: " << FLAGS_output_node; LOG(INFO) << "output node: " << FLAGS_output_node;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册