resnet weight export fix
This commit is contained in:
@@ -40,6 +40,7 @@ def print_wb_output(model, input_batch):
|
|||||||
print(i.shape)
|
print(i.shape)
|
||||||
i.tofile("debug/input.bin", format="f")
|
i.tofile("debug/input.bin", format="f")
|
||||||
|
|
||||||
|
f = None
|
||||||
for n, m in model.named_modules():
|
for n, m in model.named_modules():
|
||||||
in_output = m._value_hook
|
in_output = m._value_hook
|
||||||
print(n, ' ----------------------------------------------------------------')
|
print(n, ' ----------------------------------------------------------------')
|
||||||
@@ -48,6 +49,12 @@ def print_wb_output(model, input_batch):
|
|||||||
t = '-'.join(n.split('.'))
|
t = '-'.join(n.split('.'))
|
||||||
o.tofile("debug/" + t + ".bin", format="f")
|
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._parameters)
|
||||||
print(m.type)
|
print(m.type)
|
||||||
|
|
||||||
@@ -65,20 +72,19 @@ def print_wb_output(model, input_batch):
|
|||||||
b = np.array(b, dtype=np.float32)
|
b = np.array(b, dtype=np.float32)
|
||||||
print (" bias shape:", np.shape(b))
|
print (" bias shape:", np.shape(b))
|
||||||
else:
|
else:
|
||||||
b = np.array(o, dtype=np.float32)*0
|
b = np.zeros(w.shape[0], dtype=np.float32)
|
||||||
print (" bias shape:", np.shape(b))
|
print (" bias shape:", np.shape(b))
|
||||||
|
|
||||||
if 'BatchNorm2d' in str(m.type):
|
if 'BatchNorm2d' in str(m.type):
|
||||||
s = np.array(o, dtype=np.float32)*0+1
|
s = np.zeros(w.shape[0], dtype=np.float32)+1
|
||||||
|
|
||||||
f = open("layers/" + t + ".bin", mode='wb')
|
|
||||||
|
|
||||||
if 'BatchNorm2d' in str(m.type):
|
|
||||||
s.tofile(f, format="f")
|
s.tofile(f, format="f")
|
||||||
|
|
||||||
w.tofile(f, format="f")
|
w.tofile(f, format="f")
|
||||||
b.tofile(f, format="f")
|
b.tofile(f, format="f")
|
||||||
|
|
||||||
|
if 'BatchNorm2d' in str(m.type) or 'Linear' in str(m.type):
|
||||||
f.close()
|
f.close()
|
||||||
|
f = None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user