Options#
Configuration objects and presets for all renderers.
API Reference#
- class visualkeras.options.LayeredOptions(to_file=None, min_z=20, min_xy=20, max_z=400, max_xy=2000, scale_z=1.5, scale_xy=4.0, type_ignore=None, index_ignore=None, color_map=None, one_dim_orientation='z', index_2D=<factory>, 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, sizing_mode='accurate', dimension_caps=None, relative_base_size=20, connector_fill='gray', connector_width=1, image_fit='fill', image_axis='z', layered_groups=None, logo_groups=None, logos_legend=False, styles=None)[source]#
Bases:
objectTyped configuration bundle for
visualkeras.layered_view().This dataclass mirrors the keyword arguments accepted by
layered_viewso a layered configuration can be defined once and reused across multiple renders.The fields correspond directly to the parameters documented on
visualkeras.layered_view(). Use this object when you want to keep layered sizing, labeling, grouping, connector styling, and per-layer overrides together as one reusable configuration.LayeredOptionsis most useful when the same visual style should be applied to several related models, notebooks, or documentation examples. It keeps a long list of renderer settings in one typed object rather than repeating them across many calls.The class is intentionally thin. It does not introduce a second styling system or any extra resolution rules beyond what
layered_viewalready supports. Its main job is to make a layered configuration easier to read, store, and reuse.- Parameters:
to_file (str | None) –
min_z (int) –
min_xy (int) –
max_z (int) –
max_xy (int) –
scale_z (float) –
scale_xy (float) –
one_dim_orientation (str) –
background_fill (Any) –
draw_volume (bool) –
draw_reversed (bool) –
padding (int) –
text_callable (Callable[[int, Any], Tuple[str, bool]] | None) –
text_vspacing (int) –
spacing (int) –
draw_funnel (bool) –
shade_step (int) –
legend (bool) –
legend_text_spacing_offset (int) –
font (Any) –
font_color (Any) –
show_dimension (bool) –
sizing_mode (str) –
relative_base_size (int) –
connector_fill (Any) –
connector_width (int) –
image_fit (str) –
image_axis (str) –
- __init__(to_file=None, min_z=20, min_xy=20, max_z=400, max_xy=2000, scale_z=1.5, scale_xy=4.0, type_ignore=None, index_ignore=None, color_map=None, one_dim_orientation='z', index_2D=<factory>, 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, sizing_mode='accurate', dimension_caps=None, relative_base_size=20, connector_fill='gray', connector_width=1, image_fit='fill', image_axis='z', layered_groups=None, logo_groups=None, logos_legend=False, styles=None)#
- Parameters:
to_file (str | None) –
min_z (int) –
min_xy (int) –
max_z (int) –
max_xy (int) –
scale_z (float) –
scale_xy (float) –
one_dim_orientation (str) –
background_fill (Any) –
draw_volume (bool) –
draw_reversed (bool) –
padding (int) –
text_callable (Callable[[int, Any], Tuple[str, bool]] | None) –
text_vspacing (int) –
spacing (int) –
draw_funnel (bool) –
shade_step (int) –
legend (bool) –
legend_text_spacing_offset (int) –
font (Any) –
font_color (Any) –
show_dimension (bool) –
sizing_mode (str) –
relative_base_size (int) –
connector_fill (Any) –
connector_width (int) –
image_fit (str) –
image_axis (str) –
- Return type:
None
- class visualkeras.options.GraphOptions(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, styles=None, image_fit='contain', circular_crop=True, layered_groups=None)[source]#
Bases:
objectTyped configuration bundle for
visualkeras.graph_view().The fields correspond directly to the parameters documented on
visualkeras.graph_view(). Use this object when you want to preserve a consistent graph layout, connector style, node presentation, and image or grouping behavior across multiple renders.GraphOptionsworks well when topology diagrams should share the same spacing, node sizing, connector styling, and image treatment across several models. It is especially useful in projects that generate many related figures and want a stable visual language.Like the other options classes, this object is only a structured container for renderer arguments. It uses the same precedence model as the renderer itself when combined with presets and explicit keyword overrides.
- Parameters:
- __init__(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, styles=None, image_fit='contain', circular_crop=True, layered_groups=None)#
- Parameters:
- Return type:
None
- class visualkeras.options.FunctionalOptions(to_file=None, color_map=None, background_fill='white', padding=20, column_spacing=80, row_spacing=40, component_spacing=80, connector_fill='gray', connector_width=2, connector_arrow=False, connector_padding=5, min_z=20, min_xy=20, max_z=400, max_xy=2000, scale_z=1.5, scale_xy=4.0, one_dim_orientation='z', sizing_mode='balanced', dimension_caps=None, relative_base_size=20, text_callable=None, text_vspacing=4, font=None, font_color='black', add_output_nodes=False, layout_iterations=4, virtual_node_size=12, render_virtual_nodes=False, draw_volume=False, orientation_rotation=None, shade_step=10, image_fit='fill', image_axis='z', layered_groups=None, logo_groups=None, logos_legend=False, simple_text_visualization=False, simple_text_label_mode='below', collapse_enabled=False, collapse_rules=None, collapse_annotations=True, styles=None)[source]#
Bases:
objectTyped configuration bundle for
visualkeras.functional_view().The fields correspond directly to the parameters documented on
visualkeras.functional_view(). Use this object when you want to keep functional layout controls, connector routing, sizing behavior, collapse rules, annotations, and style overrides together as one reusable configuration.FunctionalOptionsis the most useful options class when your models have richer graph structure and the configuration naturally includes many related decisions about spacing, collapse behavior, annotation style, and per-layer rendering rules.It is still only a container for renderer arguments. The renderer remains the authoritative source for parameter behavior, and explicit keyword arguments still override values stored in the options object.
- Parameters:
to_file (str | None) –
background_fill (Any) –
padding (int) –
column_spacing (int) –
row_spacing (int) –
component_spacing (int) –
connector_fill (Any) –
connector_width (int) –
connector_arrow (bool) –
connector_padding (int) –
min_z (int) –
min_xy (int) –
max_z (int) –
max_xy (int) –
scale_z (float) –
scale_xy (float) –
one_dim_orientation (str) –
sizing_mode (str) –
relative_base_size (int) –
text_callable (Callable[[int, Any], Tuple[str, bool]] | None) –
text_vspacing (int) –
font (Any) –
font_color (Any) –
add_output_nodes (bool) –
layout_iterations (int) –
virtual_node_size (int) –
render_virtual_nodes (bool) –
draw_volume (bool) –
orientation_rotation (float | None) –
shade_step (int) –
image_fit (str) –
image_axis (str) –
simple_text_visualization (bool) –
simple_text_label_mode (str) –
collapse_enabled (bool) –
collapse_annotations (bool) –
- __init__(to_file=None, color_map=None, background_fill='white', padding=20, column_spacing=80, row_spacing=40, component_spacing=80, connector_fill='gray', connector_width=2, connector_arrow=False, connector_padding=5, min_z=20, min_xy=20, max_z=400, max_xy=2000, scale_z=1.5, scale_xy=4.0, one_dim_orientation='z', sizing_mode='balanced', dimension_caps=None, relative_base_size=20, text_callable=None, text_vspacing=4, font=None, font_color='black', add_output_nodes=False, layout_iterations=4, virtual_node_size=12, render_virtual_nodes=False, draw_volume=False, orientation_rotation=None, shade_step=10, image_fit='fill', image_axis='z', layered_groups=None, logo_groups=None, logos_legend=False, simple_text_visualization=False, simple_text_label_mode='below', collapse_enabled=False, collapse_rules=None, collapse_annotations=True, styles=None)#
- Parameters:
to_file (str | None) –
background_fill (Any) –
padding (int) –
column_spacing (int) –
row_spacing (int) –
component_spacing (int) –
connector_fill (Any) –
connector_width (int) –
connector_arrow (bool) –
connector_padding (int) –
min_z (int) –
min_xy (int) –
max_z (int) –
max_xy (int) –
scale_z (float) –
scale_xy (float) –
one_dim_orientation (str) –
sizing_mode (str) –
relative_base_size (int) –
text_callable (Callable[[int, Any], Tuple[str, bool]] | None) –
text_vspacing (int) –
font (Any) –
font_color (Any) –
add_output_nodes (bool) –
layout_iterations (int) –
virtual_node_size (int) –
render_virtual_nodes (bool) –
draw_volume (bool) –
orientation_rotation (float | None) –
shade_step (int) –
image_fit (str) –
image_axis (str) –
simple_text_visualization (bool) –
simple_text_label_mode (str) –
collapse_enabled (bool) –
collapse_annotations (bool) –
- Return type:
None
- class visualkeras.options.LenetOptions(to_file=None, min_xy=20, max_xy=220, scale_xy=4.0, type_ignore=None, index_ignore=None, color_map=None, background_fill='black', padding=20, layer_spacing=40, map_spacing=4, max_visual_channels=12, connector_fill='gray', connector_width=1, patch_fill='#7db7ff', patch_outline='black', patch_scale=1.0, patch_alpha_on_image=140, seed=None, draw_connections=True, draw_patches=True, font=None, font_color='white', top_label_padding=6, bottom_label_padding=6, top_label=True, bottom_label=True, styles=None)[source]#
Bases:
objectTyped configuration bundle for
visualkeras.lenet_view().The fields correspond directly to the parameters documented on
visualkeras.lenet_view(). Use this object when you want to preserve a consistent LeNet-style layout, connector behavior, patch styling, label spacing, and per-layer overrides across multiple renders.LenetOptionsis most helpful when publication-oriented LeNet-style figures should share the same stack spacing, label treatment, patch appearance, and embedded-image behavior across several examples.As with the other options classes, this dataclass does not change renderer semantics. It provides a clearer, reusable way to package a LeNet-style configuration before passing it to
lenet_vieworshow.- Parameters:
to_file (str | None) –
min_xy (int) –
max_xy (int) –
scale_xy (float) –
background_fill (Any) –
padding (int) –
layer_spacing (int) –
map_spacing (int) –
max_visual_channels (int) –
connector_fill (Any) –
connector_width (int) –
patch_fill (Any) –
patch_outline (Any) –
patch_scale (float) –
patch_alpha_on_image (int) –
seed (int | None) –
draw_connections (bool) –
draw_patches (bool) –
font (Any) –
font_color (Any) –
top_label_padding (int) –
bottom_label_padding (int) –
top_label (bool) –
bottom_label (bool) –
- __init__(to_file=None, min_xy=20, max_xy=220, scale_xy=4.0, type_ignore=None, index_ignore=None, color_map=None, background_fill='black', padding=20, layer_spacing=40, map_spacing=4, max_visual_channels=12, connector_fill='gray', connector_width=1, patch_fill='#7db7ff', patch_outline='black', patch_scale=1.0, patch_alpha_on_image=140, seed=None, draw_connections=True, draw_patches=True, font=None, font_color='white', top_label_padding=6, bottom_label_padding=6, top_label=True, bottom_label=True, styles=None)#
- Parameters:
to_file (str | None) –
min_xy (int) –
max_xy (int) –
scale_xy (float) –
background_fill (Any) –
padding (int) –
layer_spacing (int) –
map_spacing (int) –
max_visual_channels (int) –
connector_fill (Any) –
connector_width (int) –
patch_fill (Any) –
patch_outline (Any) –
patch_scale (float) –
patch_alpha_on_image (int) –
seed (int | None) –
draw_connections (bool) –
draw_patches (bool) –
font (Any) –
font_color (Any) –
top_label_padding (int) –
bottom_label_padding (int) –
top_label (bool) –
bottom_label (bool) –
- Return type:
None
- visualkeras.options.LAYERED_TEXT_CALLABLES: Dict[str, Callable[[int, Any], Tuple[str, bool]]] = {'name': <function <lambda>>, 'name_shape': <function <lambda>>, 'shape': <function <lambda>>, 'type': <function <lambda>>}#
Built-in layer annotation callables for layered and functional renderers.
- visualkeras.options.LAYERED_PRESETS: Dict[str, LayeredOptions] = {'compact': LayeredOptions(to_file=None, min_z=20, min_xy=20, max_z=400, max_xy=2000, scale_z=1.5, scale_xy=4.0, type_ignore=None, index_ignore=None, color_map=None, one_dim_orientation='z', index_2D=(), background_fill='white', draw_volume=True, draw_reversed=False, padding=6, text_callable=None, text_vspacing=4, spacing=6, draw_funnel=True, shade_step=10, legend=False, legend_text_spacing_offset=15, font=None, font_color='black', show_dimension=False, sizing_mode='accurate', dimension_caps=None, relative_base_size=20, connector_fill='gray', connector_width=1, image_fit='fill', image_axis='z', layered_groups=None, logo_groups=None, logos_legend=False, styles=None), 'default': LayeredOptions(to_file=None, min_z=20, min_xy=20, max_z=400, max_xy=2000, scale_z=1.5, scale_xy=4.0, type_ignore=None, index_ignore=None, color_map=None, one_dim_orientation='z', index_2D=(), 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, sizing_mode='accurate', dimension_caps=None, relative_base_size=20, connector_fill='gray', connector_width=1, image_fit='fill', image_axis='z', layered_groups=None, logo_groups=None, logos_legend=False, styles=None), 'presentation': LayeredOptions(to_file=None, min_z=20, min_xy=20, max_z=400, max_xy=2000, scale_z=1.5, scale_xy=4.0, type_ignore=None, index_ignore=None, color_map=None, one_dim_orientation='z', index_2D=(), background_fill='white', draw_volume=True, draw_reversed=False, padding=20, text_callable=<function <lambda>>, text_vspacing=4, spacing=18, draw_funnel=True, shade_step=10, legend=True, legend_text_spacing_offset=15, font=None, font_color='black', show_dimension=False, sizing_mode='accurate', dimension_caps=None, relative_base_size=20, connector_fill='gray', connector_width=2, image_fit='fill', image_axis='z', layered_groups=None, logo_groups=None, logos_legend=False, styles=None)}#
Curated presets for layered renderings keyed by human-friendly names.
- visualkeras.options.GRAPH_PRESETS: Dict[str, GraphOptions] = {'compact': GraphOptions(to_file=None, color_map=None, node_size=40, background_fill='white', padding=10, layer_spacing=180, node_spacing=10, connector_fill='gray', connector_width=1, ellipsize_after=10, inout_as_tensor=True, show_neurons=True, styles=None, image_fit='contain', circular_crop=True, layered_groups=None), 'default': GraphOptions(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, styles=None, image_fit='contain', circular_crop=True, layered_groups=None), 'presentation': GraphOptions(to_file=None, color_map=None, node_size=60, background_fill='white', padding=10, layer_spacing=300, node_spacing=10, connector_fill='gray', connector_width=2, ellipsize_after=10, inout_as_tensor=True, show_neurons=True, styles=None, image_fit='contain', circular_crop=True, layered_groups=None)}#
Curated presets for graph renderings keyed by human-friendly names.
- visualkeras.options.FUNCTIONAL_PRESETS: Dict[str, FunctionalOptions] = {'compact': FunctionalOptions(to_file=None, color_map=None, background_fill='white', padding=20, column_spacing=60, row_spacing=30, component_spacing=60, connector_fill='gray', connector_width=1, connector_arrow=False, connector_padding=5, min_z=20, min_xy=20, max_z=400, max_xy=2000, scale_z=1.5, scale_xy=4.0, one_dim_orientation='z', sizing_mode='balanced', dimension_caps=None, relative_base_size=20, text_callable=None, text_vspacing=4, font=None, font_color='black', add_output_nodes=False, layout_iterations=4, virtual_node_size=12, render_virtual_nodes=False, draw_volume=False, orientation_rotation=None, shade_step=10, image_fit='fill', image_axis='z', layered_groups=None, logo_groups=None, logos_legend=False, simple_text_visualization=False, simple_text_label_mode='below', collapse_enabled=False, collapse_rules=None, collapse_annotations=True, styles=None), 'default': FunctionalOptions(to_file=None, color_map=None, background_fill='white', padding=20, column_spacing=80, row_spacing=40, component_spacing=80, connector_fill='gray', connector_width=2, connector_arrow=False, connector_padding=5, min_z=20, min_xy=20, max_z=400, max_xy=2000, scale_z=1.5, scale_xy=4.0, one_dim_orientation='z', sizing_mode='balanced', dimension_caps=None, relative_base_size=20, text_callable=None, text_vspacing=4, font=None, font_color='black', add_output_nodes=False, layout_iterations=4, virtual_node_size=12, render_virtual_nodes=False, draw_volume=False, orientation_rotation=None, shade_step=10, image_fit='fill', image_axis='z', layered_groups=None, logo_groups=None, logos_legend=False, simple_text_visualization=False, simple_text_label_mode='below', collapse_enabled=False, collapse_rules=None, collapse_annotations=True, styles=None), 'presentation': FunctionalOptions(to_file=None, color_map=None, background_fill='white', padding=20, column_spacing=120, row_spacing=50, component_spacing=100, connector_fill='gray', connector_width=2, connector_arrow=False, connector_padding=5, min_z=20, min_xy=20, max_z=400, max_xy=2000, scale_z=1.5, scale_xy=4.0, one_dim_orientation='z', sizing_mode='balanced', dimension_caps=None, relative_base_size=20, text_callable=<function <lambda>>, text_vspacing=4, font=None, font_color='black', add_output_nodes=False, layout_iterations=4, virtual_node_size=12, render_virtual_nodes=False, draw_volume=False, orientation_rotation=None, shade_step=10, image_fit='fill', image_axis='z', layered_groups=None, logo_groups=None, logos_legend=False, simple_text_visualization=False, simple_text_label_mode='below', collapse_enabled=False, collapse_rules=None, collapse_annotations=True, styles=None)}#
Curated presets for functional renderings keyed by human-friendly names.
- visualkeras.options.LENET_PRESETS: Dict[str, LenetOptions] = {'compact': LenetOptions(to_file=None, min_xy=20, max_xy=180, scale_xy=4.0, type_ignore=None, index_ignore=None, color_map=None, background_fill='black', padding=15, layer_spacing=28, map_spacing=3, max_visual_channels=12, connector_fill='gray', connector_width=1, patch_fill='#7db7ff', patch_outline='black', patch_scale=1.0, patch_alpha_on_image=140, seed=None, draw_connections=True, draw_patches=True, font=None, font_color='white', top_label_padding=6, bottom_label_padding=6, top_label=True, bottom_label=True, styles=None), 'default': LenetOptions(to_file=None, min_xy=20, max_xy=220, scale_xy=4.0, type_ignore=None, index_ignore=None, color_map=None, background_fill='black', padding=20, layer_spacing=40, map_spacing=4, max_visual_channels=12, connector_fill='gray', connector_width=1, patch_fill='#7db7ff', patch_outline='black', patch_scale=1.0, patch_alpha_on_image=140, seed=None, draw_connections=True, draw_patches=True, font=None, font_color='white', top_label_padding=6, bottom_label_padding=6, top_label=True, bottom_label=True, styles=None), 'presentation': LenetOptions(to_file=None, min_xy=20, max_xy=260, scale_xy=4.0, type_ignore=None, index_ignore=None, color_map=None, background_fill='black', padding=20, layer_spacing=55, map_spacing=5, max_visual_channels=12, connector_fill='gray', connector_width=2, patch_fill='#7db7ff', patch_outline='black', patch_scale=1.0, patch_alpha_on_image=140, seed=None, draw_connections=True, draw_patches=True, font=None, font_color='white', top_label_padding=6, bottom_label_padding=6, top_label=True, bottom_label=True, styles=None)}#
Curated presets for lenet-style renderings keyed by human-friendly names.
Using Options Objects#
Instead of passing many individual parameters, you can use options objects for cleaner code:
from visualkeras.options import LayeredOptions, LAYERED_TEXT_CALLABLES
# Define once
my_options = LayeredOptions(
spacing=15,
padding=20,
legend=True,
text_callable=LAYERED_TEXT_CALLABLES['name_shape']
)
# Reuse for all models
img = visualkeras.layered_view(model1, options=my_options)
img = visualkeras.layered_view(model2, options=my_options)
Available Presets#
All renderers include three curated presets:
‘default’ - Balanced defaults for general use
‘compact’ - Minimal spacing for tight layouts
‘presentation’ - Large, detailed output for publications and talks
# Use a preset
img = visualkeras.layered_view(model, preset='presentation')
# Or with the unified show() function
img = visualkeras.show(model, mode='layered', preset='presentation')
Available Options Classes#
LayeredOptions- Configuration for layered_view()GraphOptions- Configuration for graph_view()FunctionalOptions- Configuration for functional_view()LenetOptions- Configuration for lenet_view()
Text Callables#
Pre-defined text callable functions for annotating layers in layered view:
from visualkeras.options import LAYERED_TEXT_CALLABLES
# Available callables:
# 'name' - Layer class name
# 'type' - Full type information
# 'shape' - Output tensor shape
# 'name_shape' - Layer name and shape
visualkeras.layered_view(
model,
text_callable=LAYERED_TEXT_CALLABLES['name_shape']
).show()