Hi,
Please help me solve the following confusion:
I have 4 filters of (4,4) size. The values of these filters I want to assign to my conv2d weights and then visualize them.
Below I define my model for greyscale image. When I run the code - it works correctly.
But when I change the out_channels from 4 to 5 or 2, I expect the model to stop working as I initialize weights for 4 filters, but in output expect 5 or 2. But my model still works, returns 4 layes and no error is thrown. Why this happens?
import torch
import torch.nn as nn
import torch.nn.functional as F

class Net(nn.Module):
    
    def __init__(self, weight):
        super(Net, self).__init__()
        # assumes there are 4 grayscale filters
        self.conv = nn.Conv2d(1, 4, kernel_size=(4, 4), bias=False)
        self.conv.weight = torch.nn.Parameter(weight)

    def forward(self, x):
        conv_x = self.conv(x)
        activated_x = F.relu(conv_x)
        return conv_x, activated_x
    
weight = torch.from_numpy(filters).unsqueeze(1).type(torch.FloatTensor)
model = Net(weight)
print(model)