Complex-valued CNN layers


I’m building a complex-valued CNN whose weights are complex numbers. Initially I wanted to test a simple network, something like this:

class CNN(nn.Module):
    def __init__(self):
        super(CNN, self).__init__()
        self.conv1 = nn.Conv2d(3,16,3).to(torch.cfloat)
        self.conv2 = nn.Conv2d(16,16,3).to(torch.cfloat)
        self.fc = nn.Linear(16*600, 2).to(torch.cfloat)
    def forward(self, x):
        x = self.conv1(x)
        x = complex_relu(x)
        x = self.conv2(x)
        x = complex_relu(x)
        x = x.contiguous().view(x.size(0), -1)
        x = self.fc(x)
        x = x.abs()
        return x

However, I see this error when training this:

RuntimeError: "slow_conv2d_cuda" not implemented for 'ComplexFloat'

I have cucnn disabled already. Does it mean the conv2d layer is currently not supported for complex float/double data and weights? Is there any workaround? Before, I built a DNN the same way and no errors were returned. Thank you.

Yes, the error message suggest that complex tensors aren’t supported in convs yet.
The feature request is tracked here as well as here. The first implementations also seem to land already in e.g. this PR.

1 Like

Thanks for the info! looking forward to seeing this feature implemented.