resnet weight export fix

This commit is contained in:
Micaela Verucchi
2019-10-28 19:20:02 +01:00
parent 4ac2c87d1c
commit 058f9b795f
+13 -7
View File
@@ -40,6 +40,7 @@ def print_wb_output(model, input_batch):
print(i.shape)
i.tofile("debug/input.bin", format="f")
f = None
for n, m in model.named_modules():
in_output = m._value_hook
print(n, ' ----------------------------------------------------------------')
@@ -48,6 +49,12 @@ def print_wb_output(model, input_batch):
t = '-'.join(n.split('.'))
o.tofile("debug/" + t + ".bin", format="f")
if 'Conv2d' in str(m.type) or 'Linear' in str(m.type):
f = open("layers/" + t + ".bin", mode='wb')
if f is None:
continue
# print(m._parameters)
print(m.type)
@@ -65,20 +72,19 @@ def print_wb_output(model, input_batch):
b = np.array(b, dtype=np.float32)
print (" bias shape:", np.shape(b))
else:
b = np.array(o, dtype=np.float32)*0
b = np.zeros(w.shape[0], dtype=np.float32)
print (" bias shape:", np.shape(b))
if 'BatchNorm2d' in str(m.type):
s = np.array(o, dtype=np.float32)*0+1
f = open("layers/" + t + ".bin", mode='wb')
if 'BatchNorm2d' in str(m.type):
s = np.zeros(w.shape[0], dtype=np.float32)+1
s.tofile(f, format="f")
w.tofile(f, format="f")
b.tofile(f, format="f")
f.close()
if 'BatchNorm2d' in str(m.type) or 'Linear' in str(m.type):
f.close()
f = None