code: import torch
  import torchvision
  from torchvision import models
  from collections import namedtuple
  
  class Vgg16(torch.nn.Module):
      def __init__(self, requires_grad=False):
          super(Vgg16, self).__init__()
          vgg_pretrained_features = models.vgg16(pretrained=True).features  # 获取预训练vgg网络层
          self.slice1 = torch.nn.Sequential()
          self.slice2 = torch.nn.Sequential()
          self.slice3 = torch.nn.Sequential()
          self.slice4 = torch.nn.Sequential()
          for x in range(5):
              self.slice1.add_module(str(x), vgg_pretrained_features[x])
          for x in range(5, 10):
              self.slice2.add_module(str(x), vgg_pretrained_features[x])
          for x in range(10, 17):
              self.slice3.add_module(str(x), vgg_pretrained_features[x])
          for x in range(17, 23):
              self.slice4.add_module(str(x), vgg_pretrained_features[x])
          if not requires_grad:
              for param in self.parameters():
                  param.requires_grad = False
  
      def forward(self, X):
          h = self.slice1(X)
          h_relu1_2 = h
          h = self.slice2(h)
          h_relu2_2 = h
          h = self.slice3(h)
          h_relu3_3 = h
          h = self.slice4(h)
          h_relu4_3 = h
          vgg_outputs = namedtuple("VggOutputs", ['relu1_2', 'relu2_2', 'relu3_3', 'relu4_3'])
          # 定义一个namedtuple类型数据，并包含列表中的属性。
          out = vgg_outputs(h_relu1_2, h_relu2_2, h_relu3_3, h_relu4_3)
          return out  # 得到经过不同层的特征值
apis: torch.nn.Sequential