Complex CNN on complex images gives RuntimeError

Hi,

I am trying to train a UNet model on complex images (MRI data), and, while I can convert the model and get the complex images (both cfloat, same happens with cdouble) just fine, I get the following error during the forward pass:

RuntimeError: getCudnnDataTypeFromScalarType() not supported for ComplexDouble

And the full stack trace:

Traceback (most recent call last):
  File "<MY FOLDER>/train.py", line 105, in <module>
    main()
  File "<PYTHON FOLDER>/miniconda3/lib/python3.8/site-packages/hydra/main.py", line 32, in decorated_main
    _run_hydra(
  File "<PYTHON FOLDER>/miniconda3/lib/python3.8/site-packages/hydra/_internal/utils.py", line 344, in _run_hydra
    run_and_report(
  File "<PYTHON FOLDER>/miniconda3/lib/python3.8/site-packages/hydra/_internal/utils.py", line 199, in run_and_report
    raise ex
  File "<PYTHON FOLDER>/miniconda3/lib/python3.8/site-packages/hydra/_internal/utils.py", line 196, in run_and_report
    return func()
  File "<PYTHON FOLDER>/miniconda3/lib/python3.8/site-packages/hydra/_internal/utils.py", line 345, in <lambda>
    lambda: hydra.run(
  File "<PYTHON FOLDER>/miniconda3/lib/python3.8/site-packages/hydra/_internal/hydra.py", line 107, in run
    return run_job(
  File "<PYTHON FOLDER>/miniconda3/lib/python3.8/site-packages/hydra/core/utils.py", line 126, in run_job
    ret.return_value = task_function(task_cfg)
  File "<MY FOLDER>/train.py", line 98, in main
    start_single_process(0, n_gpu, working_dir, config)
  File "<MY FOLDER>/train.py", line 83, in start_single_process
    train_worker(config)
  File "<MY FOLDER>/train.py", line 46, in train_worker
    trainer.train()
  File "<MY FOLDER>/srcs/trainer/base.py", line 81, in train
    result = self._train_epoch(epoch)
  File "<MY FOLDER>/srcs/trainer/trainer.py", line 52, in _train_epoch
    output = self.model(data)
  File "<PYTHON FOLDER>/miniconda3/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "<MY FOLDER>/srcs/model/unet/unet.py", line 24, in forward
    x1 = self.inc(x)
  File "<PYTHON FOLDER>/miniconda3/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "<MY FOLDER>/srcs/model/unet/unet_parts.py", line 25, in forward
    return self.double_conv(x)
  File "<PYTHON FOLDER>/miniconda3/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "<PYTHON FOLDER>/miniconda3/lib/python3.8/site-packages/torch/nn/modules/container.py", line 117, in forward
    input = module(input)
  File "<PYTHON FOLDER>/miniconda3/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "<PYTHON FOLDER>/miniconda3/lib/python3.8/site-packages/torch/nn/modules/conv.py", line 423, in forward
    return self._conv_forward(input, self.weight)
  File "<PYTHON FOLDER>/miniconda3/lib/python3.8/site-packages/torch/nn/modules/conv.py", line 419, in _conv_forward
    return F.conv2d(input, weight, self.bias, self.stride,
RuntimeError: getCudnnDataTypeFromScalarType() not supported for ComplexDouble

I wasn’t although able to pinpoint the cause. Has anyone come across the same issue before?

Cudnn doesn’t support the ComplexDouble data type, so you would have to disable it via torch.backends.cudnn.enabled = False and rerun the code.

Thank you very much for the reply. Doing that causes another similar error

RuntimeError: _thnn_conv2d_forward not supported on CUDAType for ComplexFloat

For the same operation (F.conv2d)

Thanks for the update. In that case neither the cudnn nor the native conv kernels support complex inputs at the moment. As a workaround you could use tensor.unfold (same as the im2col operation) and apply a matrix multiplication using the complex inputs/fiters.

I am getting this error while running a downloaded program which i am using for my understanding. Input values are in the form of complex number but i am not be able to initialize the weights for convolutional autoencoder in complex number form. so i am getting this error anyone please help me how to initialize weights in complex number form.
Error message:
‘’‘Input type (CUDAComplexDoubleType) and weight type (torch.cuda.FloatTensor) should be the same’’’