阅读背景:

Pytorch模型迁移和迁移学习,导入部分模型参数_lu_linux的博客

来源:互联网 

Pytorch模型迁移和迁移学习

 

1. 利用resnet18做迁移学习

import torch
from torchvision import models
 
if __name__ == "__main__":
    # device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
    device = 'cpu'
    print("-----device:{}".format(device))
    print("-----Pytorch version:{}".format(torch.__version__))
 
    input_tensor = torch.zeros(1, 3, 100, 100)
    print('input_tensor:', input_tensor.shape)
    pretrained_file = "model/resnet18-5c106cde.pth"
    model = models.resnet18()
    model.load_state_dict(torch.load(pretrained_file))
    model.eval()
    out = model(input_tensor)
    print("out:", out.shape, out[0, 0:10])imp



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: