Converting Fully Connected to Convolutional Layer

Hello

I’m trying to convert a fully - connected layer to a convolutional one. My framework pipeline consists of two modules , a featurizer and a classifier. The architecture of the classifier is a simple network as described above
self.clf = nn.Sequential(
nn.Linear(M, 32),
nn.LeakyReLU(0.2),
nn.Dropout(0.2),
nn.Linear(32, 16),
nn.LeakyReLU(0.2),
nn.Dropout(0.2),
nn.Linear(16, 2),
)
I did some research but I am a bit confused how to do the transofrmation. I want to use Conv1d instead of the FC layers.

Thank’s in Advance .

Convolution with in_channels=M, out_channels=32, kernel_size=1, stride=1

Everything works fine by adding :
self.clf = nn.Sequential(
nn.Conv1d(in_channels=M, out_channels=32, kernel_size=1, stride = 1),
nn.LeakyReLU(0.2),
nn.Conv1d(in_channels=32, out_channels=16, kernel_size=1, stride=1),
nn.LeakyReLU(0.2),
nn.Conv1d(in_channels=16, out_channels=2, kernel_size=1, stride=1),
)
The only thing that i had to modify was at the forward function :

    z = z.unsqueeze(-1)
    logit = self.clf(z)
    logit = logit.squeeze(-1)

Where z was the output of an embedding + attention pooling stage
Thank’s for the help