liveBook · Manning

Call()

As explained in Deep Learning with Python, Third Edition

A Keras layer or model method that defines the forward computation applied to inputs.

In Keras, call() defines what a layer or model does during its forward pass. It receives input tensors, applies the layer’s computation, and returns output tensors. The layer is used like a function because __call__() invokes call() for you. section 3.6.2

A simple dense computation

A custom dense layer can implement call() as `y = keras.ops.matmul(inputs, self.W) + self.b`, then apply an activation when one is configured. Calling `my_dense` with a tensor shaped `(2, 784)` produces an output shaped `(2, 32)`.

Keep these roles distinct:

  • build() creates weight state when the input shape becomes known; call() uses that state to compute outputs. section 3.6.2

How Deep Learning with Python, Third Edition covers it

How deep it goes
Explains implementation with matrix multiplication and activation, while deferring broader build mechanics to adjacent treatment.
Examples
Uses a SimpleDense layer that multiplies inputs by W, adds b, applies ReLU, and maps 784 features to 32 outputs.
What it assumes
Assumes tensors, layers, weights, and matrix multiplication while showing their use within a custom layer.
What you can do after
Build it from scratch by implementing call() for a custom Keras layer’s forward computation.
How it connects
Connects call() to Layer, __call__(), build(), weights, forward pass, and automatic shape inference.

Also explained in

Compare how 2 books explain call() →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with Python, Third Edition. The section links point to the parts of the book it draws on.