TypeError: Sequential.__init__() takes from 1 to 3 positional arguments but 4 were given

Question:

Am not able to declare the model due to problems in input_shape

input_shape = [x_train_scaled.shape[1]]
input_shape

Output –
[6]

model = tf.keras.Sequential(
    tf.keras.layers.Dense(units=64, input_shape=input_shape, activation='relu'),
    tf.keras.layers.Dense(units=64, activation='relu'),
    tf.keras.layers.Dense(units=1)
)
model.summary()

Error shown : TypeError: Sequential.init() takes from 1 to 3 positional arguments but 4 were given

I was trying to declare a sequential model but am getting typeError

Asked By: LordRaleigh

||

Answers:

From https://www.tensorflow.org/api_docs/python/tf/keras/Sequential#args_1 :

layers: Optional list of layers to add to the model

you need to pass your layers as a list when instantiating the sequential object Instead of individual arguments like you are doing now:

tf.keras.Sequential(
    layers=[
        tf.keras.layers.Dense(units=64, input_shape=input_shape, activation='relu'),
        tf.keras.layers.Dense(units=64, activation='relu'),
        tf.keras.layers.Dense(units=1)
    ],
    name=None
) 
Answered By: Mathieu Roze
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.