I want to print the output in image of each layer just like picture above
how can I do it??
class CNN(nn.Module):

    def __init__(self):
        super(CNN, self).__init__()
        self.layer1 = nn.Sequential(
            nn.Conv2d(1, 32, kernel_size = 3, stride = 1, padding = 1),
            nn.ReLU(),
            nn.MaxPool2d(kernel_size = 2, stride = 2))
    
        self.layer2 = nn.Sequential(
            nn.Conv2d(32, 64, kernel_size = 3, stride = 1, padding =1),
            nn.ReLU(),
            nn.MaxPool2d(kernel_size = 2, stride = 2))
    
        self.fc = nn.Linear(7 * 7 * 64, 10, bias = True) #0~9 10개
        torch.nn.init.xavier_uniform(self.fc.weight)
    
    def forward(self, x):
        out = self.layer1(x)
        imgprt = out.numpy()
        imgplot = plt.imshow(imgprt)
        out = torch.from_numpy(out)
        out = self.layer2(out)
        out = out.view(out.size(0), -1)
        out = self.fc(out)
        return out


RuntimeError: Can't call numpy() on Variable that requires grad. Use var.detach().numpy() instead.

i tried to change the data type in numpy and use plt.imshow() in forward but didn’t work.