Convert a Keras model to dot format. Arguments: model: A Keras model instance. show_shapes: whether to display shape information. show_layer_names: whether to display layer names. rankdir: `rankdir` argument passed to PyDot, a string specifying the format of the plot:
(model,
show_shapes=False,
show_layer_names=True,
rankdir='TB',
expand_nested=False,
dpi=96,
subgraph=False)
| 67 | |
| 68 | @keras_export('keras.utils.model_to_dot') |
| 69 | def model_to_dot(model, |
| 70 | show_shapes=False, |
| 71 | show_layer_names=True, |
| 72 | rankdir='TB', |
| 73 | expand_nested=False, |
| 74 | dpi=96, |
| 75 | subgraph=False): |
| 76 | """Convert a Keras model to dot format. |
| 77 | |
| 78 | Arguments: |
| 79 | model: A Keras model instance. |
| 80 | show_shapes: whether to display shape information. |
| 81 | show_layer_names: whether to display layer names. |
| 82 | rankdir: `rankdir` argument passed to PyDot, |
| 83 | a string specifying the format of the plot: |
| 84 | 'TB' creates a vertical plot; |
| 85 | 'LR' creates a horizontal plot. |
| 86 | expand_nested: whether to expand nested models into clusters. |
| 87 | dpi: Dots per inch. |
| 88 | subgraph: whether to return a `pydot.Cluster` instance. |
| 89 | |
| 90 | Returns: |
| 91 | A `pydot.Dot` instance representing the Keras model or |
| 92 | a `pydot.Cluster` instance representing nested model if |
| 93 | `subgraph=True`. |
| 94 | |
| 95 | Raises: |
| 96 | ImportError: if graphviz or pydot are not available. |
| 97 | """ |
| 98 | from tensorflow.python.keras.layers import wrappers |
| 99 | from tensorflow.python.keras.engine import sequential |
| 100 | from tensorflow.python.keras.engine import network |
| 101 | |
| 102 | if not check_pydot(): |
| 103 | if 'IPython.core.magics.namespace' in sys.modules: |
| 104 | # We don't raise an exception here in order to avoid crashing notebook |
| 105 | # tests where graphviz is not available. |
| 106 | print('Failed to import pydot. You must install pydot' |
| 107 | ' and graphviz for `pydotprint` to work.') |
| 108 | return |
| 109 | else: |
| 110 | raise ImportError('Failed to import pydot. You must install pydot' |
| 111 | ' and graphviz for `pydotprint` to work.') |
| 112 | |
| 113 | if subgraph: |
| 114 | dot = pydot.Cluster(style='dashed', graph_name=model.name) |
| 115 | dot.set('label', model.name) |
| 116 | dot.set('labeljust', 'l') |
| 117 | else: |
| 118 | dot = pydot.Dot() |
| 119 | dot.set('rankdir', rankdir) |
| 120 | dot.set('concentrate', True) |
| 121 | dot.set('dpi', dpi) |
| 122 | dot.set_node_defaults(shape='record') |
| 123 | |
| 124 | sub_n_first_node = {} |
| 125 | sub_n_last_node = {} |
| 126 | sub_w_first_node = {} |
no test coverage detected