data_preprocess = transforms.Compose([
        #transforms.RandomResizedCrop(224),
        transforms.ToTensor(),
        transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
    ])

def preprocess_input(img):
  x = data_preprocess(img)
  return x.unsqueeze_(0).to(device)

def display_img_pred_and_heatmap(path,model,label=None):
  original_img = cv.imread(path)
  original_img = cv.resize(original_img, (224,224))
  #print("original_img: " , original_img.shape)
  row_size = original_img.shape[0]
  col_size = original_img.shape[1]
  plt.imshow(cv.cvtColor(original_img, cv.COLOR_BGR2RGB))
  plt.show()
  preprocessed_img = preprocess_input(original_img)
  sub_model = nn.Sequential(*list(model.children())[:-1])
  print("sub_model: ",sub_model)
  print("sub_model(preprocessed_img).shape: ",sub_model(preprocessed_img).shape)

I am getting a similar error when I try to get output from an intermediate layer. I don’t get any errors when I try to get output from the complete model. How should I fix it?
RuntimeError: Given groups=1, weight of size [1024, 512, 3, 3], expected input[1, 200, 14, 14] to have 512 channels, but got 200 channels instead
Update: I don’t get any error when I change sub_model = nn.Sequential(*list(model.children())[:-1]) to sub_model = nn.Sequential(*list(model.children())[:-6])
This is my model:
class myModel5(nn.Module):

    def __init__(self, features, num_classes=200, **kwargs):
        super(myModel5, self).__init__()
        self.features = features
        self.conv6 = nn.Conv2d(512,  1024, kernel_size=3, padding=1) 
        self.conv7 = nn.Conv2d(1024, num_classes, kernel_size=1)
        self.conv8 = nn.Conv2d(512,  1024, kernel_size=3, padding=1) 
        self.conv9 = nn.Conv2d(1024, num_classes, kernel_size=1)
        self.relu = nn.ReLU(inplace=False)
        self.avgpool = nn.AdaptiveAvgPool2d(1)
        #self.fc = nn.Linear(1024, num_classes)
        initialize_weights(self.modules(), init_mode='he')
    def forward(self, x, labels=None, return_cam=False):
        batch_size = x.shape[0]
        x1 = self.features(x)
        x1 = self.conv6(x1)
        x1 = self.relu(x1)
        x1 = self.conv7(x1)
        x1 = self.relu(x1)
        x2 = self.features(x)
        x2 = self.conv8(x2)
        x2 = self.relu(x2)
        x2 = self.conv9(x2)
        x2 = self.relu(x2)
        x = x1 + x2