Reputation: 123
I was going through the tf2.0 documentation https://www.tensorflow.org/beta/tutorials/load_data/csv and could not understand a part of the following code
for units in hidden_units:
x = tf.keras.layers.Dense(units, activation='relu')(x)
outputs = tf.keras.layers.Dense(1, activation='sigmoid')(x)
what does (x) mean at the end of 2nd line and what does it do? is it a part of TensorFlow or it's available in python as well?
Upvotes: 0
Views: 44
Reputation: 27042
(x)
is just the invocation of the function returned by tf.keras.layers.Dense(units, activation='relu')
passing x
as first positional parameter.
This is not something TensorFlow related, but pure Python. In fact, every keras layer (like Dense
) just defines a callable object (like a python function) that can, thus, be called.
For instance, you can do something like:
class A:
def __init__(self):
self.a = 1
def __call__(self, parameter):
self.a = parameter
print("function called. a set to ", self.a)
x = A() #x is a callable object because of the __call__ definition
# Thus you can call it:
x(19)
Upvotes: 1