ivannz / cplxmodule

Complex-valued neural networks for pytorch and Variational Dropout for real and complex layers.
MIT License
134 stars 27 forks source link

Complex max pooling #17

Closed NEGU93 closed 3 years ago

NEGU93 commented 3 years ago

Is there an implementaion of a complex max pooling?

ivannz commented 3 years ago

Complex max pooling, i assume, would be a split activation, meaning that it would be applied to the real and imag components independently. In this case, you could do the following:

import torch

from torch.nn import MaxPool2d

from cplxmodule import Cplx
from cplxmodule.nn import CplxToCplx

input = Cplx(real=torch.randn(1, 4, 8, 8), imag=torch.randn(1, 4, 8, 8))

# create a split-layer
CplxMaxPool2d = CplxToCplx[MaxPool2d]

layer = CplxMaxPool2d(2, 2)

layer(input)

You can see a couple of other examples in the README of cplxmodule.nn

NEGU93 commented 3 years ago

Actually, that would destroy the phase information as the max of real and imaginary can be from different indices. I was thinking more about the way listed in Cao et al. "Pixel-Wise PolSAR Image Classification via a Novel Complex-Valued Deep Fully Convolutional Network" or Zhang et al. "Complex-Valued Convolutional Neural Network and Its Application in Polarimetric SAR Image Classification".

In both cases, they apply the max-pooling to the absolute value. PS: The output, however, must still be complex of course. The comparison of a>b is done with the absolute value.

ivannz commented 3 years ago

I apologise for ignoring your issue for so long @NEGU93 . I have implemented the core functions and the layers for the max-pooling you requested. Below is the abstract description of the operation

image

The split-layer max-pooling above can also be used.

i hope the layers are still relevant to your work or research.