1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

dnn: change .model file format to put layer number at the end of file

currently, the layer number is at the beginning of the .model file,
so we have to scan twice in python script, the first scan to get the
layer number. Only one scan needed after put the layer number at the
end of .model file.

Signed-off-by: Guo, Yejun <yejun.guo@intel.com>
Signed-off-by: Pedro Arthur <bygrandao@gmail.com>
This commit is contained in:
Guo, Yejun 2019-08-29 13:53:41 +08:00 committed by Pedro Arthur
parent 09a455a246
commit 2d5e39c13e
2 changed files with 3 additions and 11 deletions

View File

@ -93,8 +93,10 @@ DNNModel *ff_dnn_load_model_native(const char *model_filename)
} }
model->model = (void *)network; model->model = (void *)network;
avio_seek(model_file_context, file_size - 4, SEEK_SET);
network->layers_num = (int32_t)avio_rl32(model_file_context); network->layers_num = (int32_t)avio_rl32(model_file_context);
dnn_size = 4; dnn_size = 4;
avio_seek(model_file_context, 0, SEEK_SET);
network->layers = av_mallocz(network->layers_num * sizeof(Layer)); network->layers = av_mallocz(network->layers_num * sizeof(Layer));
if (!network->layers){ if (!network->layers){

View File

@ -129,15 +129,6 @@ class TFConverter:
self.converted_nodes.add(node.name) self.converted_nodes.add(node.name)
def generate_layer_number(self):
# in current hard code implementation, the layer number is the first data written to the native model file
# it is not easy to know it at the beginning time in the general converter, so first do a dry run for compatibility
# will be refined later.
with open('/tmp/tmp.model', 'wb') as f:
self.dump_layers_to_file(f)
self.converted_nodes.clear()
def dump_layers_to_file(self, f): def dump_layers_to_file(self, f):
for node in self.nodes: for node in self.nodes:
if node.name in self.converted_nodes: if node.name in self.converted_nodes:
@ -157,10 +148,9 @@ class TFConverter:
def dump_to_file(self): def dump_to_file(self):
self.generate_layer_number()
with open(self.outfile, 'wb') as f: with open(self.outfile, 'wb') as f:
np.array([self.layer_number], dtype=np.uint32).tofile(f)
self.dump_layers_to_file(f) self.dump_layers_to_file(f)
np.array([self.layer_number], dtype=np.uint32).tofile(f)
def generate_name_node_dict(self): def generate_name_node_dict(self):