RuntimeError: Given groups=1, weight of size [32, 1, 3, 3], expected input[1, 3, 6, 7] to have 1 channels, but got 3 channels instead
There is 6x7 numpy array:
&lt;class 'numpy.ndarray'&gt;
[[[0 0 0 0 0 0 0]
  [0 0 0 0 0 0 0]
  [0 0 0 0 0 0 0]
  [0 0 0 0 0 0 0]
  [0 0 0 0 0 0 0]
  [0 0 0 0 0 0 0]]]

Model is training normally, when it is passed to this network:
class Net(BaseFeaturesExtractor):
    def __init__(self, observation_space: gym.spaces.Box, features_dim: int = 256):
        super(Net, self).__init__(observation_space, features_dim)
        # We assume CxHxW images (channels first)
        # Re-ordering will be done by pre-preprocessing or wrapper
        # n_input_channels = observation_space.shape[0]
        n_input_channels = 1
        print(&quot;Input channels:&quot;, n_input_channels)
        self.cnn = nn.Sequential(
            nn.Conv2d(n_input_channels, 32, kernel_size=3, stride=1, padding=1),
            nn.ReLU(),
            nn.Conv2d(32, 64, kernel_size=3, stride=1, padding=1),
            nn.ReLU(),
            nn.Conv2d(64, 128, kernel_size=3, stride=1, padding=0),
            nn.ReLU(),
            nn.Flatten(),
        )

        # Compute shape by doing one forward pass
        with th.no_grad():
            n_flatten = self.cnn(
                th.as_tensor(observation_space.sample()[None]).float()
            ).shape[1]

        self.linear = nn.Sequential(nn.Linear(n_flatten, features_dim), nn.ReLU())

    def forward(self, observations: th.Tensor) -&gt; th.Tensor:
        return self.linear(self.cnn(observations))

6x7 numpy array is modified to 3x6x7 numpy array:
&lt;class 'numpy.ndarray'&gt;

[[[0 0 0 0 0 0 0]
  [0 0 0 0 0 0 0]
  [0 0 0 0 0 0 0]
  [0 0 0 0 0 0 0]
  [0 0 0 0 0 0 0]
  [0 0 0 0 0 0 0]]

 [[0 0 0 0 0 0 0]
  [0 0 0 0 0 0 0]
  [0 0 0 0 0 0 0]
  [0 0 0 0 0 0 0]
  [0 0 0 0 0 0 0]
  [0 0 0 0 0 0 0]]

 [[0 0 0 0 0 0 0]
  [0 0 0 0 0 0 0]
  [0 0 0 0 0 0 0]
  [0 0 0 0 0 0 0]
  [0 0 0 0 0 0 0]
  [1 1 1 1 1 1 1]]]

After modifying the array, it is giving this error:

RuntimeError: Given groups=1, weight of size [32, 1, 3, 3], expected
input[1, 3, 6, 7] to have 1 channels, but got 3 channels instead

In order to solve this problem, I have tried to change the number of channels:
n_input_channels = 3

However, now it is showing this error:

RuntimeError: Given groups=1, weight of size [32, 3, 3, 3], expected
input[1, 1, 6, 7] to have 3 channels, but got 1 channels instead

How can I make network accept 3x6x7 array?
Update:
I provide more code to make my case clear:
6x7 input array case:
...
board = np.array(self.obs['board']).reshape(1, self.rows, self.columns)
# board = board_3layers(self.obs.mark, board)
print(type(board))
print(board)
return board

Output:
&lt;class 'numpy.ndarray'&gt;
[[[0 0 0 0 0 0 0]
  [0 0 0 0 0 0 0]
  [0 0 0 0 0 0 0]
  [0 0 0 0 0 0 0]
  [0 0 0 0 0 0 0]
  [0 0 0 0 0 0 0]]]

Number of channels is 3:
n_input_channels = 1

It is working.
I am trying to modify array to 3x6x7:
board = np.array(self.obs['board']).reshape(1, self.rows, self.columns)
board = board_3layers(self.obs.mark, board)
print(type(board))
print(board)
return board

Output:
&lt;class 'numpy.ndarray'&gt;
[[[0 0 0 0 0 0 0]
  [0 0 0 0 0 0 0]
  [0 0 0 0 0 0 0]
  [0 0 0 0 0 0 0]
  [0 0 0 0 0 0 0]
  [0 0 0 0 0 0 0]]

 [[0 0 0 0 0 0 0]
  [0 0 0 0 0 0 0]
  [0 0 0 0 0 0 0]
  [0 0 0 0 0 0 0]
  [0 0 0 0 0 0 0]
  [0 0 0 0 0 0 0]]

 [[0 0 0 0 0 0 0]
  [0 0 0 0 0 0 0]
  [0 0 0 0 0 0 0]
  [0 0 0 0 0 0 0]
  [0 0 0 0 0 0 0]
  [1 1 1 1 1 1 1]]]

Number of channels is 3:
    n_input_channels = 3

I do not understand why it is showing this error:
RuntimeError: Given groups=1, weight of size [32, 3, 3, 3], expected input[1, 1, 6, 7] to have 3 channels, but got 1 channels instead


Your model can work with either 1 channel input, or 3 channels input, but not both.
If you set n_input_channels=1, you can work with 1x6x7 input arrays.
If you set n_input_channels=3, you can work with 3x6x7 input arrays.
You must pick one of the options - you cannot have them both simultanously.
