Complex-Valued Neural Networks in Keras with Tensorflow
Status
keras-complex works with current TensorFlow and Keras 3. It is maintained as time allows: it gets fixes when TensorFlow or Keras change, and issues and pull requests are welcome. New features are not planned.
CI tests every change against the latest TensorFlow with Keras 3 on Python 3.11 to 3.13, and against Keras 2 through TensorFlow 2.15 and through tf-keras.
Not working in this release: spectral pooling, spectral_parametrization=True, WeightNorm_Conv, SqrtInit, the fft module, and training ComplexConv1D with transposed=True. They fail on Keras 2 as well, so they were already broken before the Keras 3 update.
Complex-valued convolutions could provide some interesting results in signal processing-based deep learning. A simple(-ish) idea is including explicit phase information of time series in neural networks. This code enables complex-valued convolution in convolutional neural networks in keras with the TensorFlow backend. This makes the network modular and interoperable with standard keras layers and operations.
This repository is based on the code which reproduces experiments presented in the paper Deep Complex Networks. It is a port to Keras with Tensorflow-backend.
Requirements
- Python 3.11 or later
- TensorFlow 2.15 or later
Keras 3 (TensorFlow 2.16 and later) and Keras 2 both work. To use Keras 2 with a newer TensorFlow, install tf-keras and set TF_USE_LEGACY_KERAS=1 before TensorFlow is first imported.
Installation
pip install keras-complex
Usage
Build your neural networks with the help of keras.
import complexnn
import keras
from keras import models
from keras import layers
from keras import optimizers
model = models.Sequential()
model.add(complexnn.conv.ComplexConv2D(32, (3, 3), activation='relu', padding='same', input_shape=(28, 28, 2)))
model.add(complexnn.bn.ComplexBatchNormalization())
model.add(layers.MaxPooling2D((2, 2), padding='same'))
model.compile(optimizer=optimizers.Adam(), loss='mse')
An example working implementation of an autoencoder can be found here.
Complex Format of Tensors
This library assumes that complex values are split into two real-valued parts. The real-valued and complex-valued complement, also seen in the Docs.
The tensors for a 2D complex tensor of 3x3, the look like:
[[[r r r],
[r r r],
[r r r]],
[i,i,i],
[i,i,i],
[i,i,i]]]
So multiple samples should then be arranged into [r,r,r,i,i,i], which is also documented in the Docs.
Citation
Find the CITATION file or cite this software version as:
@misc{dramsch2019complex,
title = {Complex-Valued Neural Networks in Keras with Tensorflow},
url = {https://figshare.com/articles/Complex-Valued_Neural_Networks_in_Keras_with_Tensorflow/9783773/1},
DOI = {10.6084/m9.figshare.9783773},
publisher = {figshare},
author = {Dramsch, Jesper S{\"o}ren and Contributors},
year = {2019}
}
Please cite the original work as:
@ARTICLE {Trabelsi2017,
author = "Chiheb Trabelsi, Olexa Bilaniuk, Ying Zhang, Dmitriy Serdyuk, Sandeep Subramanian, João Felipe Santos, Soroush Mehri, Negar Rostamzadeh, Yoshua Bengio, Christopher J Pal",
title = "Deep Complex Networks",
journal = "arXiv preprint arXiv:1705.09792",
year = "2017"
}
Metadata
Release files for keras-complex 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| keras_complex-0.3.0.tar.gz | 132.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| keras_complex-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 161.2 kB
Release files / keras_complex-0.3.0.tar.gz
| Download URL | keras_complex-0.3.0.tar.gz |
|---|---|
| Size | 132.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a060b3848afd6c6cb1bbc7ba31701ca73cdb536f350b872b6445b781dc6394a1
|
|
BLAKE2b-256 checksum How to use checksums |
fc22ffc3f6d975cd6c33ac1cedba676798e627b3b46ef42f089d08378623e233
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 12, 2026.
Transparency logRelease files / keras_complex-0.3.0-py3-none-any.whl
| Download URL | keras_complex-0.3.0-py3-none-any.whl |
|---|---|
| Size | 28.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9afdd253162c943ab64b150a3541560c778bd905a5aea0fa8587744020586bc6
|
|
BLAKE2b-256 checksum How to use checksums |
8f3bdb0e8491571f76b164b10ffce84da4bfe7256b8ed4ba86b5e2331b65ddf0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 12, 2026.
Transparency log