【Pytorch】模型权重保存与上传

1.模型权重保存 torch.save

python 复制代码
model_name = args.model
if model_name == "ResNet18" or model_name == "ResNet34":
    from models.ResNet1 import BasicBlock
    from models.ResNet1 import ResNet as PATCHMODEL
if model_name == "ResNet18":
	net = PATCHMODEL(BasicBlock, [2, 2, 2, 2], num_classes=num_classes).cuda()
	
torch.save(net.state_dict(), weights_dir + '/' + model_name + '_train_loss_min_numCls{}.pth'.format(num_classes))

2.模型权重上传 load_state_dict

python 复制代码
model_name = args.model
if model_name == "ResNet18" or model_name == "ResNet34":
    from models.ResNet1 import BasicBlock
    from models.ResNet1 import ResNet as PATCHMODEL
if model_name == "ResNet18":
    model = PATCHMODEL(BasicBlock, [2, 2, 2, 2], num_classes=num_classes).cuda()
    
model.load_state_dict(torch.load(model_path), strict=False)
相关推荐
棒棒的皮皮1 天前
【深度学习】YOLO核心原理介绍
人工智能·深度学习·yolo·计算机视觉
哥布林学者1 天前
吴恩达深度学习课程五:自然语言处理 第一周:循环神经网络 (二)循环神经网络
深度学习·ai
AI数据皮皮侠1 天前
中国乡村旅游重点村镇数据
大数据·人工智能·python·深度学习·机器学习
danyang_Q1 天前
d2l安装(miniforge+cuda+pytorch)
人工智能·pytorch·python
民乐团扒谱机2 天前
【微科普】BERT 主题建模 + 多模态分析,解锁阆中古镇评论数据价值
人工智能·深度学习·bert
Keep_Trying_Go2 天前
accelerate 深度学习分布式训练库的使用详细介绍(单卡/多卡分布式训练)
人工智能·pytorch·分布式·深度学习
光羽隹衡2 天前
深度学习----PyTorch框架(手写数字识别案例)
人工智能·pytorch·深度学习
deephub2 天前
DecEx-RAG:过程监督+智能剪枝,让大模型检索推理快6倍
人工智能·深度学习·大语言模型·agent·剪枝·reg
brent4232 天前
DAY44 Dataset和Dataloader类
python·深度学习
人工智能培训2 天前
10分钟了解向量数据库(2)
人工智能·深度学习·机器学习·cnn·智能体