I am getting an error while trying to learn Tensorflow

77 Views Asked by At

This is my code:

model = keras.models.Sequential([
    keras.layers.Flatten(60000,28,28),
    keras.layers.Dense(128, activation ="relu"),
    keras.layers.Dense(10),
])

This is the output:

TypeError                                 Traceback (most recent call last)
<ipython-input-14-dc603c39e27e> in <cell line: 1>()
      1 model = keras.models.Sequential([
----> 2     keras.layers.Flatten(60000,28,28),
      3     keras.layers.Dense(128, activation ="relu"),
      4     keras.layers.Dense(10),
      5 ])
TypeError: Flatten.__init__() takes from 1 to 2 positional arguments but 4 were given

What can I do to solve this?

1

There are 1 best solutions below

0
AlbertDang On

I think at the first layer, you're supposed to use tf.keras.layers.InputLayer for your input instead of tf.keras.layers.Flatten. Flatten is used to "flatten out" a multidimensional input into an onedimensional one (usually used to transition from a convolutional layer to a fully connected dense layer).

Your code should be:

model = keras.models.Sequential([
    keras.layers.InputLayer(input_shape = (60000,28,28)),
    keras.layers.Dense(128, activation ="relu"),
    keras.layers.Dense(10),
])