最近尝试将基于tensorflow的facenet模型转化成百度开MDL模型,有如下总结:
先看一下大体处理步骤:
int main(int argc, char **args) {
try {
if (argc <= 2) {
throw string("input parameter no error, an example is : ... ");
}
int main(int argc, char **args) {
try {
if (argc <= 2) {
throw string("input parameter no error, an example is : ... ");
}
const char *_tfpb = args[1];
//g_proto -- tensorflow::GraphDef 类型
bool _success1 = read_proto_from_pb(_tfpb, &g_proto);
if (!_success1) {
throw string("read_proto_from_text failed");
}
//g_proto -- tensorflow::GraphDef 类型
bool _success1 = read_proto_from_pb(_tfpb, &g_proto);
if (!_success1) {
throw string("read_proto_from_text failed");
}
//TODO: g_ios_gpu 相关
//分析输入的pb文件,存储需要的信息
tensorflow::GraphDef g_proto_split;
setup_splits(g_proto, &g_proto_split );
//分析输入的pb文件,存储需要的信息
tensorflow::GraphDef g_proto_split;
setup_splits(g_proto, &g_proto_split );
//读取原始输入的shape
read_input_shape (g_shape_map);
read_input_shape (g_shape_map);
//node_types 是一个记录了转换后所有节点类型的set
g_node_count = g_proto_split.node_size();
for ( int i = 0 ; i < g_proto_split.node_size() ; i ++ ) {
node_types.insert( g_proto_split.node(i).op());
}
const char *mdl_json = "tfmodel.min.json";
#ifdef NEED_QUANTI
const char *mdl_data = "tfdata.min.bin";
#else
const char *mdl_data = "tfdata.bin";
#endif
//输出 json和bin文件 这些json bin文件是构成mdl网络的输入条件
dump_json(mdl_json);
dump_with_quantification(mdl_data);
}
catch (const string &msg) {
cout << msg << endl;
}
g_node_count = g_proto_split.node_size();
for ( int i = 0 ; i < g_proto_split.node_size() ; i ++ ) {
node_types.insert( g_proto_split.node(i).op());
}
const char *mdl_json = "tfmodel.min.json";
#ifdef NEED_QUANTI
const char *mdl_data = "tfdata.min.bin";
#else
const char *mdl_data = "tfdata.bin";
#endif
//输出 json和bin文件 这些json bin文件是构成mdl网络的输入条件
dump_json(mdl_json);
dump_with_quantification(mdl_data);
}
catch (const string &msg) {
cout << msg << endl;
}
}
这些是个人的思路,肯定有错误和不全的地方。且项目由于不可抗原因暂停了,只能当记录和参考。
tf模型训练的直接结果是.meta .data文件,.pb文件是用类似freeze.py转换而来,原