layers.Dense - AttributeError: 'tuple' object has no attribute 'rank' "

I am getting the error "AttributeError: ‘tuple’ object has no attribute ‘rank’ " on the line :
dense = layers.Dense(4, activation=act_func)(inputs),
in the following function :

def gen_model(act_func = ‘relu’):
inputs = keras.Input(shape=(length,))
dense = layers.Dense(4, activation=act_func)(inputs)
dense = layers.Dense(4, activation=act_func)(dense)
outputs = keras.layers.Dense(1)(dense)
model = keras.Model(inputs=inputs, outputs=outputs, name=“NN_heat_controller”)
return model

if I just print out variable “inputs”, it is :
“<KerasTensor shape=(None, 4), dtype=float32, sparse=None, name=keras_tensor_1>”

As far as I understand, the layers.Dense function is expecting a symbolic tensor and that is what is being input as well.

Hi @muhabdullahd, I have tried to create the above model in colab and I did not face any errors. The error is due to some where in your code you are using the rank method on the tuple object which is not available. Please refer to this gist for working code example. Thank You.

1 Like