def getallweights(model):
# get weights from model
model_list = MD.model2list(model)
weight_np = None
for i in range(len(model_list)):
model_state_dict = model_list[i].state_dict()
for k, d in model_state_dict.items():
k_split = k.split(".")
if k_split[-1] == "weight":
d_np = d.cpu().numpy()
d_np = d_np.reshape(d_np.size, 1)
if weight_np is None:
weight_np = d_np
else:
weight_np = np.row_stack((weight_np, d_np))
return weight_np
评论列表
文章目录