Thank you very much, I posted my code below:
from __future__ import print_function, division
import torch
import torch.nn as nn
import torch.optim as optim
from torch.optim import lr_scheduler
from torch.autograd import Variable
import torchvision
from torchvision import datasets, models, transforms
import time
import os
from PIL import Image
import matplotlib.pyplot as plt
import torch.nn.functional as F

plt.ion()   # interactive mode
data_transforms = {
    'val': transforms.Compose([
        transforms.Resize(256),
        transforms.CenterCrop(224),
        transforms.ToTensor(),
        transforms.Normalize([0.5,0.5,0.5], [0.5,0.5,0.5])
    ]),
}

data_dir = 'feature_pic/'
image_datasets = {x: datasets.ImageFolder(os.path.join(data_dir, x),
                                          data_transforms[x])
                  for x in ['val']}
dataloaders = {x: torch.utils.data.DataLoader(image_datasets[x], batch_size=2,
                                             shuffle=False, num_workers=4)
              for x in ['val']}
dataset_sizes = {x: len(image_datasets[x]) for x in ['val']}
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")

class FeatureExtractor(nn.Module):
    def __init__(self, submodule, extracted_layers):
        super(FeatureExtractor,self).__init__()
        self.submodule = submodule
        self.extracted_layers= extracted_layers
    def forward(self, x):
        outputs = []
        for name, module in self.submodule._modules.items():
            if name is "fc": x = x.view(x.size(0), -1)
            x = module(x)
            if name in self.extracted_layers:
                outputs.append(x)
        return outputs

# Iterate over data.
def visualize_picture(model):
    model.eval()
    for i, (inputs, labels) in enumerate(dataloaders['val']):
        inputs = inputs.to(device)
        labels = labels.to(device)         
        exact_list=["conv2","layer2","avgpool"]
        myexactor=FeatureExtractor(model,exact_list)

        y=myexactor(inputs)  

        #特征输出可视化
        for i in range(4):
            ax = plt.subplot(2, 2, i + 1)
            #ax.set_title('Sample #{}'.format(i))
            ax.axis('off')
            plt.imshow(y[0].data.cpu().numpy()[0,i,:,:],cmap='jet')
            plt.show()
            plt.savefig('feature.png')

myresnet =torch.load("./checkpoint/model.pkl")
myresnet = myresnet.to(device)
visualize_picture(myresnet)
plt.ioff()
plt.show()

I think there may be a problem with the model I loaded, because I saved the entire network. If I only load the parameters, I don’t know how to do it.Thanks