首页 Paddle框架 帖子详情
paddle如何保存模型状态字典
收藏
快速回复
Paddle框架 问答模型训练 536 0
paddle如何保存模型状态字典
收藏
快速回复
Paddle框架 问答模型训练 536 0

paddle应该如何保存状态字典,使用paddle.save(ckpt,path)会报错

 

代码:

def ckpt_save(val_dict, model, optimizer, save_path):
    ckpt = {
        'acc': val_dict['acc_now'],
        'loss': val_dict['loss_now'],
        'epoch': val_dict['epoch_now'],
        'model_state_dict': model.state_dict(),
        'optimizer_state_dict': optimizer.state_dict(),
    }
    paddle.save(ckpt, save_path)

 

File "E:\0_Python\02_git\segmentation_paddle\my_utils\net_prepare.py", line 455, in model_save
ckpt_save(val_dict, model, optimizer, Model_ckpt_path)
File "E:\0_Python\02_git\segmentation_paddle\my_utils\net_prepare.py", line 469, in ckpt_save
paddle.save(ckpt, save_path)
File "C:\Users\12458\AppData\Local\Programs\Python\Python36\lib\site-packages\paddle\framework\io.py", line 289, in save
pickle.dump(saved_obj, f, protocol=pickle_protocol)
TypeError: can't pickle ParamBase objects

0
收藏
回复
需求/bug反馈?一键提issue告诉我们
发现bug?如果您知道修复办法,欢迎提pr直接参与建设飞桨~
在@后输入用户全名并按空格结束,可艾特全站任一用户