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()
原文:https://www.cnblogs.com/dyclown/p/13170884.html