pytorch必备技能

1.模型的序列化 反序列化(没啥用但是基础的前置知识)

torch.save(什么都可以,文件的路径)

        保存整个模型:torch.save(model,模型路径)

        加载整个模型 torch.load(保存模型的路径)

        保存模型参数: 

                state_dict  = model.state_dict()

                torch.save(state_dict,模型路径)

torch.load(文件的路径,指定的存放位置)

2.断点续训练:意外中断后继续训练 真的很重要

https://github.com/JansonYuan/Pytorch-Camp/blob/master/hello%20pytorch/lesson/lesson-28/checkpoint_resume.pyhttps://github.com/JansonYuan/Pytorch-Camp/blob/master/hello%20pytorch/lesson/lesson-28/checkpoint_resume.py

 

 3.标签,类别名转换

4.取输出向量最大值的标号就是预测值

        _,predicted = torch.max(model(输入),1)

おすすめ

転載: blog.csdn.net/weixin_45955767/article/details/120694037