graph_view#

scikitplot.visualkeras.graph_view(model, to_file=None, color_map=None, node_size=50, background_fill='white', padding=10, layer_spacing=250, node_spacing=10, connector_fill='gray', connector_width=1, ellipsize_after=10, inout_as_tensor=True, show_neurons=True, backend=None, show_os_viewer=False, save_fig=True, save_fig_filename='', overwrite=True, add_timestamp=False, verbose=False)[source]#

Generates an architectural visualization for a given linear Keras tf.keras.Model model (i.e., one input and output tensor for each layer) in graph style.

Parameters:
modeltensorflow.keras.Model

A Keras tf.keras.Model model to be visualized.

to_filestr, optional

Path to the file where the generated image will be saved. The file type is inferred from the file extension. If None, the image is not saved.

Changed in version 0.4.0: The to_file is now deprecated, and will be removed in a future release. Users are encouraged to use 'save_fig' and 'save_fig_filename' instead for improved compatibility.

color_mapdict, optional

A dictionary defining the fill and outline colors for each layer type. Layers not specified will use default (None uses default colors).

node_sizeint, optional

The size (in pixels) of each node (default is 50).

background_fillstr or tuple, optional

Background color of the image (default is “white”). Can be a string or a tuple (R, G, B, A).

paddingint, optional

Padding before and after layers (default is 10). Distance (in pixels) before the first and after the last layer in the visualization.

layer_spacingint, optional

Horizontal spacing (in pixels) between consecutive layers (default is 250).

node_spacingint, optional

Horizontal spacing (in pixels) between nodes within the layer (default is 10).

connector_fillstr or tuple, optional

Color of connectors between layers (default is “gray”). Can be a string or a tuple (R, G, B, A).

connector_widthint, optional

Line width (in pixels) of the connectors between nodes (default is 1).

ellipsize_afterint, optional

Maximum number of neurons per layer to visualize. Layers exceeding this limit will represent the remaining neurons as ellipses (default is 10).

inout_as_tensorbool, optional

If True, one input and output node will be created for each tensor. If False, tensors will be flattened, and one node for each scalar will be created (e.g., a tensor with shape (10, 10) will be represented by 100 nodes) (default is True).

show_neuronsbool, optional

If True, each neuron in supported layers will be represented as a node (subject to ellipsize_after limit). If False, each layer is represented by a single node (default is True).

backendbool, str, optional

Specifies the backend used to process and save the image. If the value is one of 'matplotlib', 'true', or 'none' (case-insensitive), the Matplotlib backend will be used. This is useful for better DPI control and consistent rendering. Any other value will fall back to using the PIL backend. Common values include:

  • 'matplotlib', 'true', 'none' : Use Matplotlib

  • 'pil', 'fast', etc. : Use PIL (Python Imaging Library)

Default is None.

Added in version 0.4.0: The backend parameter was added to allow switching between PIL and Matplotlib.

show_os_viewerbool, optional

If True, displays the saved image (by PIL) in the system’s default image viewer using PIL’s .show() method. Default is False.

Added in version 0.4.0.

save_figbool, default=True

Save the plot.

Added in version 0.4.0.

save_fig_filenamestr, optional, default=’’

Specify the path and filetype to save the plot. If nothing specified, the plot will be saved as png to the current working directory. Defaults to name to use func.__name__.

Added in version 0.4.0.

overwritebool, optional, default=True

If False and a file exists, auto-increments the filename to avoid overwriting.

Added in version 0.4.0.

add_timestampbool, optional, default=False

Whether to append a timestamp to the filename. Default is False.

Added in version 0.4.0.

verbosebool, optional

If True, enables verbose output with informative messages during execution. Useful for debugging or understanding internal operations such as backend selection, font loading, and file saving status. If False, runs silently unless errors occur.

Default is False.

Added in version 0.4.0: The verbose parameter was added to control logging and user feedback verbosity.

Returns:
PIL.Image.Image

The generated image visualizing the model’s architecture.

Parameters:
  • to_file (Optional[str])

  • color_map (Optional["Dict"])

  • node_size (int)

  • background_fill (Any)

  • padding (int)

  • layer_spacing (int)

  • node_spacing (int)

  • connector_fill (Any)

  • connector_width (int)

  • ellipsize_after (int)

  • inout_as_tensor (bool)

  • show_neurons (bool)

  • backend (Optional[Union[bool,str]])

  • show_os_viewer (bool)

  • save_fig (bool)

  • save_fig_filename (str)

  • overwrite (bool)

  • verbose (bool)

Return type:

PIL.Image.Image