Giving a two-dimensional size to layer

I have started to use keras very recently

I am trying to convert a julia code to a python code by using keras.

In julia, I have the following line:

Ωp_nn = Lux.Chain(Lux.Dense(1,32), Lux.Dense(32,32,tanh), Lux.Dense(32,32,tanh), Lux.Dense(32,2))

And python-keras version of this line should be:

[layers_] = [layers.Dense((1,32),activation="tanh"),layers.Dense((32,32),activation="tanh"),layers.Dense((32,32)activation="tanh"),layers.Dense((32,2),activation="tanh")]

However, I see that I am not allowed the give the shape as tuples i.e (32,32). I can only give a number/integer because I am having the following error:

int() argument must be a string, a bytes-like object or a number, not 'tuple'

Is there any way to work around it?

Thank you!

Hi @keras_vs_julia, Welcome to the Tensorflow Forum!

You are facing this error because, the first argument for the dense layer will be the units(Positive integer, dimensionality of the output space). But you are passing as tuple (1,32). If you want to pass 2D as input to the layer, you can mention the shape to the input_shape argument. For example:

layers_ = [layers.Dense(32,activation="tanh",input_shape=(1,32)),

Thank You.

Thank you!!

Is it possible to use it like that:

from tensorflow.keras import layers,initializers
from keras.models import Sequential
from keras.layers import Dense
from keras.activations import tanh

omegap_nn = Sequential([
    Dense(32, activation="tanh",input_shape=(1,32)),
    Dense(32, activation=tanh),input_shape=(32,32)),
    Dense(32, activation=tanh),input_shape=(32,32)),

Or instead of sequential, should I keep them as list?

For training a model you should use it as sequential. Thank You