Converting Conv2d to Conv3d

Hello.

I want to convert a 2D Conv into 3D Conv for video RGB input.
Since, I am new to pytorch, it would be grateful if anyone can help me.

Thank you in advance.

class EmbeddingNet(nn.Module):
    def __init__(self):
        super(EmbeddingNet, self).__init__()
        self.convnet = nn.Sequential(nn.Conv2d(3, 32, 5), nn.PReLU(),
                                     nn.MaxPool2d(2, stride=2),
                                     nn.Conv2d(32, 64, 5), nn.PReLU(),
                                     nn.MaxPool2d(2, stride=2))

        self.fc = nn.Sequential(nn.Linear(64 * 61 * 61, 256),
                                nn.PReLU(),
                                nn.Linear(256, 256),
                                nn.PReLU(),
                                nn.Linear(256, 2)
                                )

    def forward(self, x):
        output = self.convnet(x)
        output = output.view(output.size()[0], -1)
        output = self.fc(output)
        return output

    def get_embedding(self, x):
        return self.forward(x)

@ptrblck Any suggestions on this? I really appreciate if you help

From the code perspective you could replace all ...2d layers with their ...3d equivalents first.
If you want to reuse the ...2d parameters, you would have to come up with a way to copy these parameters into the ...3d modules and expand/repeat them.
I don’t have any information unfortunately, which approach would work best, as I assume it’s use case dependent.
However, if you want to train the new model from scratch, replacing the layers might work without any further changes.

Thank you for your suggestion.