Not a professional here but here is how I’d approach the situation.
Here is what I understood from your question, you have downloaded a pre-trained model, and now you want to change the internal channels of the layers, but keep the layers themselves, right?
Would you mind explaining further why you would need to do this? Maybe it would shed some light on how best to solve the issue.
I’m not sure if you can change the channels without hurting the weights because you’d have to reinitialize the layers to get the channels you want.
A solution might be to use the pre-trained model as an encoder, pass your data through the encoder, then create a custom network and pass it through. e.g
class CustomCNN(nn.Module):
    def __init__(self, encoder):
        super(CustomCNN, self).__init__()
        # pass the pretrained model here
        self.encoder = encoder
        # define your custom architecture
        self.features = nn.Sequential(
            nn.Conv2d(3, 6, (5, 5)),
            nn.ReLU(),
            nn.MaxPool2d((2, 2)),
            nn.Conv2d(6, 8, (5, 5)),
            nn.ReLU(),
            nn.MaxPool2d((2, 2))
        )
        self.fc = nn.Sequential(
            nn.Linear(200, 40),
            nn.Linear(40, 10)
        )

    def forward(self, x):
       # pass through encoder first
        x = self.encoder(x)
        x = self.features(x)
        x = torch.flatten(x, 1)
        x = self.fc(x)
        return x

model = CustomCNN()

This way, your model works on whatever channels you have.



 dhkim:

and now I want to change the input and output channels of all layers. Not only the first or last layers


I’m not sure this is possible because you have to redefine
The tricky part would be how to match the output shape of the encoder to your first Conv2D.