-1

I am trying to figure out how to use Keras and came across some syntax I'm not familiar with and don't know what to search for. I figured it would be easier to just show someone.

What is going on with the last part of lines 2, 3, and 4? I'm asking about the (inputs) and (x) at the end of the lines.

inputs = keras.Input(shape=(784,), name="digits")
x = layers.Dense(64, activation="relu", name="dense_1")(inputs)
x = layers.Dense(64, activation="relu", name="dense_2")(x)
outputs = layers.Dense(10, activation="softmax", name="predictions")(x)
Shane P
  • 3
  • 4

1 Answers1

0

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

This code means that you are giving the layer "inputs" as inputs to the layer "x".

Simply put, if you want to give a certain layer as input to the current layer you write it in parenthesis like this.

It is the same for the other layers, passing the previous layer as input to the current layer and so on.

Mohammad Alavi
  • 912
  • 1
  • 6
  • 16
  • 2
    While this probably answers the keras specific part (I know nothing about it) of the question, the answer could be extended by a syntax explanation. I guess `layer.Dense` returns an object, that has a `__call__` method. This method is executed by `(...)` – MofX Apr 28 '21 at 09:24