pub fn sequential_model_summary<F: Float + Debug + ScalarOperand>(
model: &Sequential<F>,
input_shape: Option<Vec<usize>>,
title: Option<&str>,
options: Option<ModelVizOptions>,
) -> Result<String>
Expand description
Create an ASCII text representation of a sequential model architecture
§Arguments
model
- The sequential model to visualizeinput_shape
- Optional input shape to propagate through the modeltitle
- Optional title for the visualizationoptions
- Visualization options
§Returns
Result<String>
- ASCII representation of the model architecture
Examples found in repository?
examples/model_visualization_simple.rs (lines 17-31)
9fn main() -> Result<()> {
10 // Initialize random number generator
11 let mut rng = SmallRng::seed_from_u64(42);
12
13 // Create a simple MLP model
14 let model = create_mlp_model(&mut rng)?;
15
16 // Display model summary
17 let summary = sequential_model_summary(
18 &model,
19 Some(vec![32, 784]), // Input shape (batch_size, input_features)
20 Some("Simple MLP Neural Network"),
21 Some(ModelVizOptions {
22 width: 80,
23 show_params: true,
24 show_shapes: true,
25 show_properties: true,
26 color_options: ColorOptions {
27 enabled: true,
28 ..Default::default()
29 },
30 }),
31 )?;
32 println!("{}", summary);
33
34 // Display model dataflow
35 let dataflow = sequential_model_dataflow(
36 &model,
37 vec![32, 784], // Input shape
38 Some("MLP Data Flow Diagram"),
39 None, // Use default options
40 )?;
41 println!("\n{}", dataflow);
42
43 Ok(())
44}
More examples
examples/model_visualization_cnn.rs (lines 17-31)
9fn main() -> Result<()> {
10 // Initialize random number generator
11 let mut rng = SmallRng::seed_from_u64(42);
12
13 // Create a CNN model
14 let model = create_cnn_model(&mut rng)?;
15
16 // Display model summary
17 let summary = sequential_model_summary(
18 &model,
19 Some(vec![32, 3, 224, 224]), // Input shape (batch_size, channels, height, width)
20 Some("CNN Architecture"),
21 Some(ModelVizOptions {
22 width: 100,
23 show_params: true,
24 show_shapes: true,
25 show_properties: true,
26 color_options: ColorOptions {
27 enabled: true,
28 ..Default::default()
29 },
30 }),
31 )?;
32 println!("{}", summary);
33
34 // Display model dataflow
35 let dataflow = sequential_model_dataflow(
36 &model,
37 vec![32, 3, 224, 224], // Input shape
38 Some("CNN Data Flow Diagram"),
39 Some(ModelVizOptions {
40 width: 80,
41 show_params: true,
42 show_shapes: true,
43 show_properties: false,
44 color_options: ColorOptions {
45 enabled: true,
46 ..Default::default()
47 },
48 }),
49 )?;
50 println!("\n{}", dataflow);
51
52 Ok(())
53}
examples/model_architecture_visualization.rs (lines 21-32)
9fn main() -> Result<()> {
10 println!("Model Architecture Visualization Example");
11 println!("=======================================\n");
12
13 // Initialize RNG with a fixed seed for reproducibility
14 let mut rng = SmallRng::seed_from_u64(42);
15
16 // Example 1: MLP (Multilayer Perceptron) Architecture
17 println!("\n--- Example 1: MLP Architecture ---\n");
18 let mlp = create_mlp_model(&mut rng)?;
19
20 // Display model summary
21 let mlp_summary = sequential_model_summary(
22 &mlp,
23 Some(vec![32, 784]), // Input shape (batch_size, input_features)
24 Some("MLP Neural Network"),
25 Some(ModelVizOptions {
26 width: 80,
27 show_params: true,
28 show_shapes: true,
29 show_properties: true,
30 color_options: ColorOptions::default(),
31 }),
32 )?;
33 println!("{}", mlp_summary);
34
35 // Display model dataflow
36 let mlp_dataflow = sequential_model_dataflow(
37 &mlp,
38 vec![32, 784], // Input shape
39 Some("MLP Data Flow"),
40 None, // Use default options
41 )?;
42 println!("\n{}", mlp_dataflow);
43
44 // Example 2: CNN (Convolutional Neural Network) Architecture
45 println!("\n--- Example 2: CNN Architecture ---\n");
46 let cnn = create_cnn_model(&mut rng)?;
47
48 // Display model summary with colored output
49 let mut color_options = ColorOptions::default();
50 color_options.enabled = true; // Force enable colors
51 color_options.use_bright = true;
52
53 let cnn_summary = sequential_model_summary(
54 &cnn,
55 Some(vec![32, 28, 28, 1]), // Input shape (batch_size, height, width, channels)
56 Some("CNN Neural Network"),
57 Some(ModelVizOptions {
58 width: 80,
59 show_params: true,
60 show_shapes: true,
61 show_properties: true,
62 color_options,
63 }),
64 )?;
65 println!("{}", cnn_summary);
66
67 // Display model dataflow
68 let cnn_dataflow = sequential_model_dataflow(
69 &cnn,
70 vec![32, 28, 28, 1], // Input shape
71 Some("CNN Data Flow"),
72 Some(ModelVizOptions {
73 width: 80,
74 show_params: true,
75 show_shapes: true,
76 show_properties: false,
77 color_options,
78 }),
79 )?;
80 println!("\n{}", cnn_dataflow);
81
82 // Example 3: RNN (Recurrent Neural Network) Architecture
83 println!("\n--- Example 3: RNN (LSTM) Architecture ---\n");
84 println!("Skipping RNN example due to threading constraints with LSTM implementation.");
85
86 println!("\nModel Architecture Visualization Complete!");
87 Ok(())
88}