Skip to content

Commit e48bc45

Browse files
julienrfchollet
authored andcommitted
Fix summary about models (keras-team#8245)
* Expose and document utils.layer_utils.print_summary as utils.print_summary Fixes keras-team#8105 * Fix docs autogen when running on python 3.6.2 When a class inherits from object without defining __init__, AttributeError is raised instead of TypeError. So we need to catch both exceptions to be compatible. * Fix process_XXX_docstring functions to work with models function The process_function_docstring would fail to parse the “# Argument” and “# Returns” of class functions. This was because it expected the “# Argument” string to be preceeded by exactly a newline and 4 spaces, but for class methods, that would be a newline and 8 spaces. This fixes the problem by expecting a newline and some number of space.
1 parent 9fecc51 commit e48bc45

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

docs/autogen.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@
284284
'functions': [utils.to_categorical,
285285
utils.normalize,
286286
utils.get_file,
287+
utils.print_summary,
287288
utils.plot_model,
288289
utils.multi_gpu_model],
289290
'classes': [utils.CustomObjectScope,
@@ -360,7 +361,7 @@ def get_class_signature(cls):
360361
try:
361362
class_signature = get_function_signature(cls.__init__)
362363
class_signature = class_signature.replace('__init__', cls.__name__)
363-
except TypeError:
364+
except (TypeError, AttributeError):
364365
# in case the class inherits from object and does not
365366
# define __init__
366367
class_signature = cls.__module__ + '.' + cls.__name__ + '()'
@@ -406,8 +407,8 @@ def code_snippet(snippet):
406407

407408

408409
def process_class_docstring(docstring):
409-
docstring = re.sub(r'\n # (.*)\n',
410-
r'\n __\1__\n\n',
410+
docstring = re.sub(r'\n(\s+)# (.*)\n',
411+
r'\n\1__\2__\n\n',
411412
docstring)
412413
docstring = re.sub(r' ([^\s\\\(]+):(.*)\n',
413414
r' - __\1__:\2\n',
@@ -420,8 +421,8 @@ def process_class_docstring(docstring):
420421

421422

422423
def process_function_docstring(docstring):
423-
docstring = re.sub(r'\n # (.*)\n',
424-
r'\n __\1__\n\n',
424+
docstring = re.sub(r'\n(\s+)# (.*)\n',
425+
r'\n\1__\2__\n\n',
425426
docstring)
426427
docstring = re.sub(r' ([^\s\\\(]+):(.*)\n',
427428
r' - __\1__:\2\n',

docs/templates/models/about-keras-models.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ There are two types of models available in Keras: [the Sequential model](/models
44

55
These models have a number of methods in common:
66

7-
- `model.summary()`: prints a summary representation of your model.
7+
- `model.summary()`: prints a summary representation of your model. Shortcut for [utils.print_summary](/utils/#print_summary)
88
- `model.get_config()`: returns a dictionary containing the configuration of the model. The model can be reinstantiated from its config via:
99
```python
1010
config = model.get_config()

keras/utils/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from .generic_utils import deserialize_keras_object
1919
from .generic_utils import Progbar
2020
from .layer_utils import convert_all_kernels_in_model
21+
from .layer_utils import print_summary
2122
from .vis_utils import plot_model
2223
from .np_utils import to_categorical
2324
from .np_utils import normalize

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy