-1

I was wondering what the difference is between doing something like

dense = Dense(64)
x = dense(input)

and this

dense = Dense(64)(input)

Are these two notations equivalent?

Olli
  • 906
  • 10
  • 25

1 Answers1

1

AFTER EDIT:

No, there is no difference, they generate the same exact model.

BEFORE EDIT:

From keras functional API documentation:

You create a new node in the graph of layers by calling a layer on this inputs object:

dense = layers.Dense(64, activation="relu")
x = dense(inputs)

In the code you posted there are no assignments.

Check how the model is connected with the plot method, a layer could exist but not be connected with the rest of the model.

keras.utils.plot_model(model, "my_first_model.png")

source:

https://keras.io/guides/functional_api/

  • Thank you, I saw just now, I made an incomplete example. I meant to ask, what is the difference between dense = Dense(64) dense(input) and just dense = Dense(64)(input) – Olli Apr 19 '21 at 13:07
  • 1
    with those assigments there are no differences, it's the same thing – BestDogeStackoverflow Apr 19 '21 at 13:12