ageron / ageron/handson-ml2

[QUESTION] Why use `keras.backend` functions instead of `tf` functions?

Open
#591 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Jupyter Notebook
Stars
30k
Forks
13.1k
PR merge metrics
No merged PRs in 30d

Description

In the book and notebooks, functions from `keras.backend` are sometimes used instead of `tf` functions. For example, we might see `K = keras.backend` followed by `K.mean` instead of `tf.reduce_mean`. I am asking generally, but an example can be seen in `19_training_and_deploying_at_scale.ipynb`

```python
# ...
def train_step():
def step_fn(inputs):
X, y = inputs
with tf.GradientTape() as tape:
Y_proba = model(X)
loss = K.sum(keras.losses.sparse_categorical_crossentropy(y, Y_proba)) / batch_size

# ...
```

1. Why is this choice made?
2. Are there important reasons to use keras.backend functions instead of `tf` reduce functions like this?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.