import torch.nn as nn
import torchvision.models as models
class resnet(nn.Module):
def __init__(self):
super(resnet,self).__init__()
self.model = models.resnet18(pretrained=True)
self.encoder = nn.Sequential(*list(self.model.children())[:-1])
def forward(self,x):
y = self.encoder(x)
return y
net = resnet()
本站文章如无特殊说明,均为本站原创,如若转载,请注明出处:Pytorch加载预训练模型前n层 - Python技术站