LSTM params

This commit is contained in:
Francesco Gatti
2020-02-15 20:37:08 +01:00
parent 4fa5d2c231
commit 4746121d43
5 changed files with 111 additions and 25 deletions
+13 -3
View File
@@ -24,6 +24,8 @@ def export_layer(name, weights, bias):
weights = weights.transpose(3,2,0,1)
elif(weights.ndim == 3):
weights = weights.transpose(2,1,0)
elif(weights.ndim == 2):
weights = weights.transpose(1,0)
else:
print("Ndim", weights.ndim)
raise("not implemented with dim" )
@@ -40,13 +42,19 @@ def export_layer(name, weights, bias):
bin_write(f, bias)
print ("WEIGHTS saved\n")
def export_bidir(name, weights):
def export_bidir(name, params):
print ("######## EXPORT", name, "LAYER ########")
for w in weights:
print(np.shape(w))
f = open(name + ".bin", mode='wb')
for w in params:
#w = w.transpose()
print(np.shape(w))
bin_write(f, w)
print("WEIGHTS saved\n")
#https://github.com/fchollet/keras/wiki/Converting-convolution-kernels-from-Theano-to-TensorFlow-and-vice-versa
if __name__ == '__main__':
print("DATA FORMAT: ", keras.backend.image_data_format())
@@ -64,6 +72,7 @@ if __name__ == '__main__':
model = load_model(args.model)
model.summary()
weights = model.get_weights()
ws = np.shape(weights)
@@ -90,6 +99,7 @@ if __name__ == '__main__':
elif name.startswith("dense"):
export_layer(args.output + "/" + name, wgs[0], wgs[1])
elif name.startswith("bidirectional"):
wgs = l.forward_layer.get_weights()
export_bidir(args.output + "/" + name, wgs)
else:
print ("skip:", name, "has no weights")