2D vector to 1D vector by over convolution

hi,
I have a 10241024 dimension feature vector to reduce dimension to 1,1024, so how can I get the final dimension using conv2d operation over 10241024. please explain the forward function for this or any other way

I don’t know which dimensions are referenced by the shape [1024, 1024], but assume the spatial ones.
If so, you could use a conv layer with kernel_size=(1024, 1) to create an output of [batch_size, out_channels, 1, 1024]:

conv = nn.Conv2d(3, 4, (1024, 1))
x = torch.randn(2, 3, 1024, 1024)
out = conv(x)
print(out.shape)
# > torch.Size([2, 4, 1, 1024])

can you please explain why we use x = torch.randn(2, 3, 1024, 1024) instead of x = torch.randn(1024,1024)

nn.Conv2d expects an input in the shape [batch_size, channels, height, width] as described in the docs, so I’ve used random values for the missing dimensions.

ok. in my case its like x = torch.randn(1, 1, 1024, 1024)