ageron / ageron/handson-ml3

[BUG] Chapter 10: number of output arguments of model.evaluate(...) for multiple outputs

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

Description

**Describe the bug**
cell 81 in "10_neural_nets_with_keras.ipynb" brings up an error

**To Reproduce**
```eval_results = model.evaluate((X_test_wide, X_test_deep), (y_test, y_test))
weighted_sum_of_losses, main_loss, aux_loss, main_rmse, aux_rmse = eval_results
```

And if you got an exception, please copy the full stacktrace here:

```---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[64], line 2
1 eval_results = model.evaluate((X_test_wide, X_test_deep), (y_test, y_test))
----> 2 weighted_sum_of_losses, main_loss, aux_loss, main_rmse, aux_rmse = eval_results

ValueError: not enough values to unpack (expected 5, got 3)
```

**Expected behavior**
No errormessage

**Versions (please complete the following information):**
- OS: Win 11 Education, Build 10.0.22631
- Python: 3.12.2
- TensorFlow: 2.16.1

**Additional Info**
4 cells below, the same error occurs. In addition
`model.compile(loss="mse", loss_weights=[0.9, 0.1], optimizer=optimizer,
metrics=["RootMeanSquaredError"])
`
has to be replaced with
`model.compile(loss="mse", loss_weights=[0.9, 0.1], optimizer=optimizer,
metrics=("RootMeanSquaredError", "RootMeanSquaredError"))
`
Otherwise, the following error message appears

```
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[74], line 7
5 model.norm_layer_wide.adapt(X_train_wide)
6 model.norm_layer_deep.adapt(X_train_deep)
----> 7 history = model.fit(
8 (X_train_wide, X_train_deep), (y_train, y_train), epochs=10,
9 validation_data=((X_valid_wide, X_valid_deep), (y_valid, y_valid)))
10 eval_results = model.evaluate((X_test_wide, X_test_deep), (y_test, y_test))
11 weighted_sum_of_losses, main_loss, aux_loss, main_rmse, aux_rmse = eval_results

File C:\Programs\WPy64-31220\python-3.12.2.amd64\Lib\site-packages\keras\src\utils\traceback_utils.py:122, in filter_traceback..error_handler(*args, **kwargs)
119 filtered_tb = _process_traceback_frames(e.__traceback__)
120 # To get the full stack trace, call:
121 # `keras.config.disable_traceback_filtering()`
--> 122 raise e.with_traceback(filtered_tb) from None
123 finally:
124 del filtered_tb

File C:\Programs\WPy64-31220\python-3.12.2.amd64\Lib\site-packages\keras\src\trainers\compile_utils.py:250, in CompileMetrics._build_metrics_set(self, metrics, num_outputs, output_names, y_true, y_pred, argument_name)
248 if isinstance(metrics, (list, tuple)):
249 if len(metrics) != len(y_pred):
--> 250 raise ValueError(
251 "For a model with multiple outputs, "
252 f"when providing the `{argument_name}` argument as a "
253 "list, it should have as many entries as the model has "
254 f"outputs. Received:\n{argument_name}={metrics}\nof "
255 f"length {len(metrics)} whereas the model has "
256 f"{len(y_pred)} outputs."
257 )
258 for idx, (mls, yt, yp) in enumerate(
259 zip(metrics, y_true, y_pred)
260 ):
261 if not isinstance(mls, list):

ValueError: For a model with multiple outputs, when providing the `metrics` argument as a list, it should have as many entries as the model has outputs. Received:
metrics=['RootMeanSquaredError']
of length 1 whereas the model has 2 outputs.
```

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.