History

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.

Guo, Yejun committed 7 years ago

Commit 2d5e39c1 parent 09a455a2 files · +3 −11Browse files

Showing the changes to tools/python/convert_from_tensorflow.py (1 of 2 files). Show all

Unified · Split

tools/python/convert_from_tensorflow.py+1−11
@@ -129,15 +129,6 @@ class TFConverter: · 128 unmodified lines
129129 self.converted_nodes.add(node.name)
130130
131131
132− def generate_layer_number(self):
133− # in current hard code implementation, the layer number is the first data written to the native model file
134− # it is not easy to know it at the beginning time in the general converter, so first do a dry run for compatibility
135− # will be refined later.
136− with open('/tmp/tmp.model', 'wb') as f:
137− self.dump_layers_to_file(f)
138− self.converted_nodes.clear()
139−
140−
141132 def dump_layers_to_file(self, f):
142133 for node in self.nodes:
143134 if node.name in self.converted_nodes:
@@ -157,10 +148,9 @@ class TFConverter: · 13 unmodified lines
157148
158149
159150 def dump_to_file(self):
160− self.generate_layer_number()
161151 with open(self.outfile, 'wb') as f:
162− np.array([self.layer_number], dtype=np.uint32).tofile(f)
163152 self.dump_layers_to_file(f)
153+ np.array([self.layer_number], dtype=np.uint32).tofile(f)
164154
165155
166156 def generate_name_node_dict(self):

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t