layered_view#

scikitplot.visualkeras.layered_view(model, to_file=None, min_z=20, min_xy=20, max_z=400, max_xy=2000, scale_z=0.1, scale_xy=4, type_ignore=None, index_ignore=None, color_map=None, one_dim_orientation='z', index_2d=None, background_fill='white', draw_volume=True, draw_reversed=False, padding=10, text_callable=None, text_vspacing=4, spacing=10, draw_funnel=True, shade_step=10, legend=False, legend_text_spacing_offset=15, font=None, font_color='black', show_dimension=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 a layered style, which is particularly suitable for convolutional neural networks (CNNs).

Parameters:
modeltensorflow.keras.Model

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

to_filestr or None

Path to the file where the generated image will be saved. If the image does not exist yet it will be created, else overwritten. The file type is inferred from the file extension. If None, no file is created.

min_zint

Minimum z-dimension size (in pixels) for a layer.

min_xyint

Minimum x- and y-dimension size (in pixels) for a layer.

max_zint

Maximum z-dimension size (in pixels) for a layer.

max_xyint

Maximum x- and y-dimension size (in pixels) for a layer.

scale_zfloat

Scalar multiplier for the z-dimension size of each layer.

scale_xyfloat

Scalar multiplier for the x- and y-dimension size of each layer.

type_ignorelist of str

List of layer types to ignore when visualizing the model.

index_ignorelist of int

List of layer indices to ignore when visualizing the model.

color_mapdict

A dictionary mapping layer defining fill and outline for each layer by class type. Layers not specified in the dictionary will use default colors.

one_dim_orientation{‘x’, ‘y’, ‘z’}

Axis along which one-dimensional layers should be drawn.

index_2dlist of int

Indices of layers to be drawn in 2D when draw_volume is True.

background_fillstr or tuple

Background color of the image. Can be a string or a tuple (R, G, B, A).

draw_volumebool

Whether to use a 3D volumetric view (True) or a 2D box view (False).

draw_reversedbool

Whether to draw 3D boxes in reverse order, from front-right to back-left.

paddingint

Distance in pixels before the first and after the last layer.

text_callablecallable

A callable that generates text for layers. The callable should take two arguments: the layer index (int) and the layer (Layer).

text_vspacingint

Vertical spacing in pixels between lines of text produced by text_callable.

spacingint

Horizontal spacing in pixels between consecutive layers.

draw_funnelbool

If set to True, a funnel will be drawn between consecutive layers.

shade_stepfloat

Lightness deviation step for shades in the visualization (only applicable in 3D volumetric view).

legendbool

Whether to include a legend of the layers in the image.

legend_text_spacing_offsetfloat

Offset for the space allocated to legend text. Useful for preventing text cutoff in the legend.

fontstr or None

Font to be used for legend text. If None, the default font is used.

font_colorstr or tuple

Color of the font. Can be a string or a tuple (R, G, B, A).

show_dimensionbool

Whether to display layer dimensions in the legend (only when legend is True).

Returns:
image

The generated architecture visualization image.

Parameters:
  • to_file (str)

  • min_z (int)

  • min_xy (int)

  • max_z (int)

  • max_xy (int)

  • scale_z (float)

  • scale_xy (float)

  • type_ignore (list)

  • index_ignore (list)

  • color_map (dict)

  • one_dim_orientation (str)

  • index_2d (list)

  • background_fill (Any)

  • draw_volume (bool)

  • draw_reversed (bool)

  • padding (int)

  • text_callable (Callable[[int, Layer], tuple])

  • text_vspacing (int)

  • spacing (int)

  • draw_funnel (bool)

  • legend (bool)

  • font (<module 'PIL.ImageFont' from '/opt/conda/lib/python3.11/site-packages/PIL/ImageFont.py'>)

  • font_color (Any)

Return type:

<module ‘PIL.Image’ from ‘/opt/conda/lib/python3.11/site-packages/PIL/Image.py’>