Techno Blender
Digitally Yours.

Deep Learning Model Visualization Tools: Which is Best? | by Benjamin McCloskey | Nov, 2022

0 48


Different ways of visualizing your next deep learning model for your data science project.

*Note: I have no affiliation with the companies or APIs discussed today.

Image from Author

Visualizations are important for many reasons. They help support and solidify the messages within a body of text. Did you know that humans not only learn by reading and lectures, but they also learn by seeing? Deep learning models, ie. neural networks, can be very difficult to describe in words. Generating a visualization of a neural network you created can help the reader fully understand and examine the developed model.

The 5 tools we will look at for visualizing deep learning models today are:

  1. Microsoft Powerpoint
  2. ANN Visualizer
  3. Keras .summary() method
  4. Keras Utils model plotting function
  5. Keras Visual

Yes, the first tool for visualizing a deep learning model is Microsoft Powerpoint. I believe Powerpoint is an option for creating visualizations of deep learning models because of its accessibility, ease of use, and flexibility for the user to manipulate and control how the visual looks.

Visualization Created in PowerPoint (Image from Author)

Pros

As stated the pros of Microsoft Powerpoint are its accessibility, ease of use, and flexibility.

  1. Accessibility– Anyone who is running Microsoft products on their computer can access Powerpoint.
  2. Ease of Use– The application is very “pointy-clicky” as well. Basically, all you need to do to create a visualization is add shapes and text boxes. From there you can define their physical characteristics to make a unique final product. This ties into the flexibility of Powerpoint.
  3. Flexibility– There are so many different features in Powerpoint that allow you to create almost any representation of your model that want.
  1. It can take a long time to create a very detailed visualization.
  2. Powerpoint is still limited with how abstract of a visualization you wish to create.
  3. Powerpoint does not interface with the models created in Python like the other packages we are looking at today.

The next visualization tool is the ANN Visualizer API. All you need to do for this tool is run one line of code to print your model and then you can access the image it created.

# !pip install graphviz
import graphviz
model = Sequential()
model.add(layers.Convolution2D(32,3,3,input_shape=(28,28,1),activation= layers.LeakyReLU()))
model.add(layers.MaxPooling2D(pool_size=(2, 2)))
model.add(layers.Convolution2D(64,3,3,activation=layers.LeakyReLU()))
model.add(layers.MaxPooling2D(pool_size=(1, 1)))
model.add(layers.Flatten())
model.add(layers.Dropout(0.5))
model.add(Dense(units=10, activation='softmax'))

ann_viz(model , view=True, title= 'My Model', filename = 'output.gv')

After running this code, the API outputs the image below for your own personal use.

ANN API Image (Image from Author)

Pros

  1. Creates high-resolution images of your model.
  2. Builds models that are graph-structured making it very easy for the user to see all of the different connections.
  3. Easy-to-understand visuals.
  4. Provides the number of parameters at each layer of the deep learning model.

Cons

  1. I had to change the format of my model to blocked layers (it would not accept the other format I used for all of the other examples)
  2. Not easily accessible (in Colab) and it saves the file as a .gv file

If you are creating a model in Keras, you can use the .summary() method to print out your model and get a general summary of what it contains.

model = keras.Sequential(
[
keras.Input(shape=input_shape),
layers.Conv2D(32, kernel_size=(3, 3)),
layers.LeakyReLU(),
layers.MaxPooling2D(pool_size=(2, 2)),
layers.Conv2D(64, kernel_size=(3, 3)),
layers.LeakyReLU(),
layers.MaxPooling2D(pool_size=(2, 2)),
layers.Flatten(),
layers.Dropout(0.5),
layers.Dense(num_classes, activation="softmax"),
]
)

model.summary()

Keras .summary() Method (Image from Author)

Pros

  1. Gives you a quick summary if you are creating a model in Keras.
  2. Explicitly shows the different number of parameters within each of your model’s layers. (Even lists the total number of trainable parameters).
  3. Clearly defines each layer.

Cons

  1. Only for models developed with Keras.
  2. Does not produce an output that is visually appealing for a written report.
  3. No interactive components in the output.
  4. No color.

The Keras Utils model plotting function is one step up from the .summary() method. It creates a more visually appealing overview of a model in one line of code.

from keras.utils.vis_utils import plot_model

#Your Model code here use the Keras Sequential Architecture

plot_model(model, to_file='model_plot.png', show_shapes=True, show_layer_names=True)

Keras Util Model Plotting Function (Image from Author)

Pros

  1. More visual than the Keras .summary() method.
  2. Clearly states the input and output dimension sizes.
  3. Can be done in one line of code.

Cons

  1. Does not produce the most visually appealing images (No color!).
  2. Has to be used for a Keras Model.

Of the three different Keras methods discussed today, the Visual Keras method is the most visually appealing! Just like the other methods, this can be done in one line of code.

model = keras.Sequential(
[
keras.Input(shape=input_shape),
layers.Conv2D(32, kernel_size=(3, 3)),
layers.LeakyReLU(),
layers.MaxPooling2D(pool_size=(2, 2)),
layers.Conv2D(64, kernel_size=(3, 3)),
layers.LeakyReLU(),
layers.MaxPooling2D(pool_size=(2, 2)),
layers.Flatten(),
layers.Dropout(0.5),
layers.Dense(num_classes, activation="softmax"),
]
)

visualkeras.layered_view(model, legend=True,to_file = '/content/gdrive/MyDrive/output.png').show()

You can also say legend=False if you do not wish to have a legend as shown in the image below.

Visual Keras Model (Image from Author)

Pros

  1. Creates visually appealing images for Keras models. The API details each layer and displays them with various sizes in lengths depending on their size in the model.
  2. The API adds color to the visual, unlike the other two Keras Functions.

Cons

  1. Only for Keras Models.
  2. Does not give the various hyperparameters associated with each layer (ie. the input and output dimensions of each layer).
  3. It makes different types of layers the same color which can be very confusing (The convolution layer is the same color as the dense layer in the image above).

The final verdict for which visualization tool is best…?

It depends!

If you want to have control over all aspects of what the visualization looks like, go with Microsoft PowerPoint. The tradeoff is you will be spending much more time and labor on creating the visualization. ANN Visualizer is a great tool for showing the flow of deep learning models while making the graph visually entertaining. The biggest problem I had with the visualizer API was I had to change the setup of my neural network in Keras.

If the deep Learning model is being developed with Keras and you desire a quick summary of the model, use the Keras’ .summary() method. The trade-off for this tool is the summary is not visually appealing as well as not the best option for a written report. The Keras’ utils model plotting function may be more optimal than the .summary() method but remember that it is still not a visually grabbing image to read and does not list the trainable parameters.

If you want to create an image with Keras that is more noticeable to the reader, use Visual Keras. Visual Keras adds size and colors to deep learning models that will gain the attention of the users and clearly defines the architecture of the model. One caveat is Visual Keras does not list the values associated with each layer of a deep learning model.

If you enjoyed today’s reading, PLEASE give me a follow and let me know if there is another topic you would like me to explore! If you do not have a Medium account, sign up through my link here! Additionally, add me on LinkedIn, or feel free to reach out! Thanks for reading!


Different ways of visualizing your next deep learning model for your data science project.

*Note: I have no affiliation with the companies or APIs discussed today.

Image from Author

Visualizations are important for many reasons. They help support and solidify the messages within a body of text. Did you know that humans not only learn by reading and lectures, but they also learn by seeing? Deep learning models, ie. neural networks, can be very difficult to describe in words. Generating a visualization of a neural network you created can help the reader fully understand and examine the developed model.

The 5 tools we will look at for visualizing deep learning models today are:

  1. Microsoft Powerpoint
  2. ANN Visualizer
  3. Keras .summary() method
  4. Keras Utils model plotting function
  5. Keras Visual

Yes, the first tool for visualizing a deep learning model is Microsoft Powerpoint. I believe Powerpoint is an option for creating visualizations of deep learning models because of its accessibility, ease of use, and flexibility for the user to manipulate and control how the visual looks.

Visualization Created in PowerPoint (Image from Author)

Pros

As stated the pros of Microsoft Powerpoint are its accessibility, ease of use, and flexibility.

  1. Accessibility– Anyone who is running Microsoft products on their computer can access Powerpoint.
  2. Ease of Use– The application is very “pointy-clicky” as well. Basically, all you need to do to create a visualization is add shapes and text boxes. From there you can define their physical characteristics to make a unique final product. This ties into the flexibility of Powerpoint.
  3. Flexibility– There are so many different features in Powerpoint that allow you to create almost any representation of your model that want.
  1. It can take a long time to create a very detailed visualization.
  2. Powerpoint is still limited with how abstract of a visualization you wish to create.
  3. Powerpoint does not interface with the models created in Python like the other packages we are looking at today.

The next visualization tool is the ANN Visualizer API. All you need to do for this tool is run one line of code to print your model and then you can access the image it created.

# !pip install graphviz
import graphviz
model = Sequential()
model.add(layers.Convolution2D(32,3,3,input_shape=(28,28,1),activation= layers.LeakyReLU()))
model.add(layers.MaxPooling2D(pool_size=(2, 2)))
model.add(layers.Convolution2D(64,3,3,activation=layers.LeakyReLU()))
model.add(layers.MaxPooling2D(pool_size=(1, 1)))
model.add(layers.Flatten())
model.add(layers.Dropout(0.5))
model.add(Dense(units=10, activation='softmax'))

ann_viz(model , view=True, title= 'My Model', filename = 'output.gv')

After running this code, the API outputs the image below for your own personal use.

ANN API Image (Image from Author)

Pros

  1. Creates high-resolution images of your model.
  2. Builds models that are graph-structured making it very easy for the user to see all of the different connections.
  3. Easy-to-understand visuals.
  4. Provides the number of parameters at each layer of the deep learning model.

Cons

  1. I had to change the format of my model to blocked layers (it would not accept the other format I used for all of the other examples)
  2. Not easily accessible (in Colab) and it saves the file as a .gv file

If you are creating a model in Keras, you can use the .summary() method to print out your model and get a general summary of what it contains.

model = keras.Sequential(
[
keras.Input(shape=input_shape),
layers.Conv2D(32, kernel_size=(3, 3)),
layers.LeakyReLU(),
layers.MaxPooling2D(pool_size=(2, 2)),
layers.Conv2D(64, kernel_size=(3, 3)),
layers.LeakyReLU(),
layers.MaxPooling2D(pool_size=(2, 2)),
layers.Flatten(),
layers.Dropout(0.5),
layers.Dense(num_classes, activation="softmax"),
]
)

model.summary()

Keras .summary() Method (Image from Author)

Pros

  1. Gives you a quick summary if you are creating a model in Keras.
  2. Explicitly shows the different number of parameters within each of your model’s layers. (Even lists the total number of trainable parameters).
  3. Clearly defines each layer.

Cons

  1. Only for models developed with Keras.
  2. Does not produce an output that is visually appealing for a written report.
  3. No interactive components in the output.
  4. No color.

The Keras Utils model plotting function is one step up from the .summary() method. It creates a more visually appealing overview of a model in one line of code.

from keras.utils.vis_utils import plot_model

#Your Model code here use the Keras Sequential Architecture

plot_model(model, to_file='model_plot.png', show_shapes=True, show_layer_names=True)

Keras Util Model Plotting Function (Image from Author)

Pros

  1. More visual than the Keras .summary() method.
  2. Clearly states the input and output dimension sizes.
  3. Can be done in one line of code.

Cons

  1. Does not produce the most visually appealing images (No color!).
  2. Has to be used for a Keras Model.

Of the three different Keras methods discussed today, the Visual Keras method is the most visually appealing! Just like the other methods, this can be done in one line of code.

model = keras.Sequential(
[
keras.Input(shape=input_shape),
layers.Conv2D(32, kernel_size=(3, 3)),
layers.LeakyReLU(),
layers.MaxPooling2D(pool_size=(2, 2)),
layers.Conv2D(64, kernel_size=(3, 3)),
layers.LeakyReLU(),
layers.MaxPooling2D(pool_size=(2, 2)),
layers.Flatten(),
layers.Dropout(0.5),
layers.Dense(num_classes, activation="softmax"),
]
)

visualkeras.layered_view(model, legend=True,to_file = '/content/gdrive/MyDrive/output.png').show()

You can also say legend=False if you do not wish to have a legend as shown in the image below.

Visual Keras Model (Image from Author)

Pros

  1. Creates visually appealing images for Keras models. The API details each layer and displays them with various sizes in lengths depending on their size in the model.
  2. The API adds color to the visual, unlike the other two Keras Functions.

Cons

  1. Only for Keras Models.
  2. Does not give the various hyperparameters associated with each layer (ie. the input and output dimensions of each layer).
  3. It makes different types of layers the same color which can be very confusing (The convolution layer is the same color as the dense layer in the image above).

The final verdict for which visualization tool is best…?

It depends!

If you want to have control over all aspects of what the visualization looks like, go with Microsoft PowerPoint. The tradeoff is you will be spending much more time and labor on creating the visualization. ANN Visualizer is a great tool for showing the flow of deep learning models while making the graph visually entertaining. The biggest problem I had with the visualizer API was I had to change the setup of my neural network in Keras.

If the deep Learning model is being developed with Keras and you desire a quick summary of the model, use the Keras’ .summary() method. The trade-off for this tool is the summary is not visually appealing as well as not the best option for a written report. The Keras’ utils model plotting function may be more optimal than the .summary() method but remember that it is still not a visually grabbing image to read and does not list the trainable parameters.

If you want to create an image with Keras that is more noticeable to the reader, use Visual Keras. Visual Keras adds size and colors to deep learning models that will gain the attention of the users and clearly defines the architecture of the model. One caveat is Visual Keras does not list the values associated with each layer of a deep learning model.

If you enjoyed today’s reading, PLEASE give me a follow and let me know if there is another topic you would like me to explore! If you do not have a Medium account, sign up through my link here! Additionally, add me on LinkedIn, or feel free to reach out! Thanks for reading!

FOLLOW US ON GOOGLE NEWS

Read original article here

Denial of responsibility! Techno Blender is an automatic aggregator of the all world’s media. In each content, the hyperlink to the primary source is specified. All trademarks belong to their rightful owners, all materials to their authors. If you are the owner of the content and do not want us to publish your materials, please contact us by email – [email protected]. The content will be deleted within 24 hours.

Leave a comment