params_tocsv.py
717 Bytes
import pickle as pk
import numpy as np
import csv
x = []
with open('params.pkl', 'rb') as f, open("params.csv", "w", newline='') as out:
x = pk.load(f)
# for key in x.keys():
# print(key, " : ", x[key])
writer = csv.DictWriter(out, ['key', 'shape', 'newline'], delimiter=',')
newline_ = csv.DictWriter(out, ['newline1', 'newline2'], delimiter=',')
wr = csv.writer(out, quotechar=None)
for key_ in x.keys():
print("Writing weights -",key_)
writer.writerow({'key':key_, 'shape':x[key_].shape, 'newline':None})
data_ = x[key_]
for s in x[key_]:
wr.writerow(s.flatten())
newline_.writerow({'newline1':None, 'newline2':None})
f.close()
out.close()