Small complex-regression example

Let’s just see how we can do a regression small CVNN.

As usual, first import what is needed:

import numpy as np
import cvnn.layers as complex_layers
import tensorflow as tf

Let’s create random complex data

input_shape = (4, 28, 28, 3)
x = tf.cast(tf.random.normal(input_shape), tf.complex64)

Now let’s create our network and compile it

model = tf.keras.models.Sequential()
model.add(complex_layers.ComplexInput(input_shape=input_shape[1:]))
model.add(complex_layers.ComplexFlatten())
model.add(complex_layers.ComplexDense(units=64, activation='cart_relu'))
model.add(complex_layers.ComplexDense(units=10, activation='linear'))
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])

This is it! Now you can train uwing the fit method or predict. You can check for example that the output of the model is still complex (as expected).

y = model(x)
assert y.dtype == np.complex64