MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / plot_model

Function plot_model

tensorflow/python/keras/utils/vis_utils.py:253–300  ·  view source on GitHub ↗

Converts a Keras model to dot format and save to a file. Arguments: model: A Keras model instance to_file: File name of the plot image. show_shapes: whether to display shape information. show_layer_names: whether to display layer names. rankdir: `rankdir` argument passed to Py

(model,
               to_file='model.png',
               show_shapes=False,
               show_layer_names=True,
               rankdir='TB',
               expand_nested=False,
               dpi=96)

Source from the content-addressed store, hash-verified

251
252@keras_export('keras.utils.plot_model')
253def plot_model(model,
254 to_file='model.png',
255 show_shapes=False,
256 show_layer_names=True,
257 rankdir='TB',
258 expand_nested=False,
259 dpi=96):
260 """Converts a Keras model to dot format and save to a file.
261
262 Arguments:
263 model: A Keras model instance
264 to_file: File name of the plot image.
265 show_shapes: whether to display shape information.
266 show_layer_names: whether to display layer names.
267 rankdir: `rankdir` argument passed to PyDot,
268 a string specifying the format of the plot:
269 'TB' creates a vertical plot;
270 'LR' creates a horizontal plot.
271 expand_nested: Whether to expand nested models into clusters.
272 dpi: Dots per inch.
273
274 Returns:
275 A Jupyter notebook Image object if Jupyter is installed.
276 This enables in-line display of the model plots in notebooks.
277 """
278 dot = model_to_dot(model,
279 show_shapes=show_shapes,
280 show_layer_names=show_layer_names,
281 rankdir=rankdir,
282 expand_nested=expand_nested,
283 dpi=dpi)
284 if dot is None:
285 return
286 _, extension = os.path.splitext(to_file)
287 if not extension:
288 extension = 'png'
289 else:
290 extension = extension[1:]
291 # Save image to disk.
292 dot.write(to_file, format=extension)
293 # Return the image as a Jupyter Image object, to be displayed in-line.
294 # Note that we cannot easily detect whether the code is running in a
295 # notebook, and thus we always return the Image if Jupyter is available.
296 try:
297 from IPython import display
298 return display.Image(filename=to_file)
299 except ImportError:
300 pass

Callers

nothing calls this directly

Calls 3

model_to_dotFunction · 0.85
ImageMethod · 0.80
writeMethod · 0.45

Tested by

no test coverage detected