yxlijun / DSFD.pytorch

DSFD implement with pytorch
167 stars 58 forks source link

get a pretrained resnet model without last fc layer #19

Closed chenwuxing closed 5 years ago

chenwuxing commented 5 years ago

Hello, I have used model.children() to delete the last fc layer in resnet.

import torch
from torchvision import models

resnet50 = models.resnet50(pretrained=True)
resnet_reducefc = torch.nn.Sequential(*list(resnet50.children())[:-2])
torch.save(resnet_reducefc.state_dict(),"f:/resnet50.pth")

But when I run these code will get a error:

    res_para = torch.load("f:/resnet50.pth")

    res.load_state_dict(res_para)

微信截图_20190720145524 I think the reason may be that I use nn.sequential() to save model file, but now I don't have a good idea to deal these problem. could you give me some help,thank you!