Mixed Convolutions


I was wondering How I can have 2D convs after 3D conves layer,
Some persons proposed to have mixed convolutions
but as we know output of 3D conv has an extra dimension
if we squeeze that dimension , DO we effect the gradients?

I would appreciate your comment,

Which dimension would you like to squeeze?
The kernels will use all channels (in the default setup with groups=1) in both cases.
However, their spatial size and stride differs as they will use:

  • the height and width in nn.Conv2d
  • the depth, height, and width in nn.Conv3d

If you set out_channels=1 for the last nn.Conv3d layer, you could squeeze the channel dimension.
The next nn.Conv2d layer will use the depth dimension as the new channel dimension.
Is that what you would like to achieve?

Continuing the discussion from Mixed Convolutions:

Can I have Squeeze in nn.Sequential I mean :
self.block = nn.Sequential (nn.Conv3d (), squeezing, nn.Conv2d()) Or I have to do squeezing in just forward function?

You could write your custom squeeze layer.
Here is a small example:

class SqueezeLayer(nn.Module):
    def __init__(self, dim):
        super(SqueezeLayer, self).__init__()
        self.dim = dim
    def forward(self, x):
        return x.squeeze(self.dim)

model = nn.Sequential(
    nn.Conv3d(3, 1, 3, 1, 1),
    nn.Conv2d(24, 6, 3, 1, 1)

x = torch.randn(1, 3, 24, 24, 24)
output = model(x)
1 Like