keras-team / keras-core

A multi-backend implementation of the Keras API, with support for TensorFlow, JAX, and PyTorch.
Apache License 2.0
1.27k stars 115 forks source link

Don't show optimizer params if not optimizer or not built #885

Closed mattdangerw closed 11 months ago

mattdangerw commented 11 months ago

Most people will call summary() before fit(). Doing so will usually mean the optimizer would show up as 0 parameters, which is misleading.

mattdangerw commented 11 months ago

Alternately, we could show a (unbuilt) status.

Model: "res_net_2"
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ Layer (type)                               ┃ Output Shape                        ┃       Param # ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│ dense_6 (Dense)                            │ ?                                   │   0 (unbuilt) │
├────────────────────────────────────────────┼─────────────────────────────────────┼───────────────┤
│ dense_7 (Dense)                            │ ?                                   │   0 (unbuilt) │
├────────────────────────────────────────────┼─────────────────────────────────────┼───────────────┤
│ dense_8 (Dense)                            │ ?                                   │   0 (unbuilt) │
└────────────────────────────────────────────┴─────────────────────────────────────┴───────────────┘
 Total params: 0 (0.00 B)
 Trainable params: 0 (0.00 B)
 Non-trainable params: 0 (0.00 B)
 Optimizer params: 0 (0.00 B) (unbuilt)

In some ways this is more consistent maybe? But would also mean most people will see an unbuilt optimizer in the standard usage and not be sure how to build it.

Seemed potentially least confusing to just leave it off, but open to suggestions!

codecov[bot] commented 11 months ago

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.06% :tada:

Comparison is base (bb21710) 76.49% compared to head (a4a78a3) 76.56%. Report is 1 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #885 +/- ## ========================================== + Coverage 76.49% 76.56% +0.06% ========================================== Files 329 329 Lines 31334 31425 +91 Branches 6100 6114 +14 ========================================== + Hits 23970 24060 +90 - Misses 5785 5786 +1 Partials 1579 1579 ``` | [Flag](https://app.codecov.io/gh/keras-team/keras-core/pull/885/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=keras-team) | Coverage Δ | | |---|---|---| | [keras_core](https://app.codecov.io/gh/keras-team/keras-core/pull/885/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=keras-team) | `76.46% <100.00%> (+0.06%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=keras-team#carryforward-flags-in-the-pull-request-comment) to find out more. | [Files Changed](https://app.codecov.io/gh/keras-team/keras-core/pull/885?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=keras-team) | Coverage Δ | | |---|---|---| | [keras\_core/utils/summary\_utils.py](https://app.codecov.io/gh/keras-team/keras-core/pull/885?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=keras-team#diff-a2VyYXNfY29yZS91dGlscy9zdW1tYXJ5X3V0aWxzLnB5) | `73.11% <100.00%> (+0.38%)` | :arrow_up: | ... and [8 files with indirect coverage changes](https://app.codecov.io/gh/keras-team/keras-core/pull/885/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=keras-team)

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.