Model Integration
In this section, we will set up our classification model by either importing or building it.
Project Setup
First step is to Create a Project with the nameMNIST
, and the description Digit Classifier.
Dataset Block Setup
We'll start by pointing the model's dataset block to our mnist
dataset. This will update the Dataset Block with the relevant input.
In the Network view, click the Dataset Block to display the Dataset Details panel on the right, then click Connect Dataset and select the mnist
dataset from the list.
A more detailed explanation about this step can be found at Dataset Block.
Set Model Layers
Importing a Model from Tensorflow or PyTorch
Tensorleap can import a model saved by Tensorflow (PB/H5/JSON_TF2) and PyTorch (ONNX). For more information, see Import Model.
In this sample code, a simple CNN model is created using Tensorflow and then saved as a file named mnist-cnn.h5
.
For your convenience, you can also download this file here:
Import Model
Set the Revision Name to
mnist-cnn
and the Model Name topre-trained
.For File Type, select
H5_TF2,
then choosemnist-cnn.h5
in the Upload File field.Click the Import button.
Back in the Network view, set the Dataset Block to point to the
mnist
Dataset.
Once all layers have been connected to each other, the model should look like this:
Each block shows the calculated output shape affected by the preceding layers.
Add Loss and Optimizer
In this section, we will set the Categorical Crossentropy loss function, and connect it to both the dataset's ground truth and the last layer in our model. We'll then add an Adam Optimizer block and connect it to the loss block. For more information, see Loss and Optimizer.
After completing this section, our model will be ready for training.
Within the Network view:
Right-click and add the following:
Loss -> CategoricalCrossentropy
GroundTruth, and set it to
Ground Truth - classes
Optimizer -> Adam
Connect the last Dense layer and the GroundTruth to the CategoricalCrossentropy block. Additionally, connect the Loss block to the Adam optimizer.
All steps are illustrated below.
Add Visualizers
Visualizers define how to display tensors within the model graph. For more info, see Visualizers.
Dataset Input Visualizer
There must be at least one visualizer connected to the model's input for analysis. To add the Visualizer for the input, follow the steps below.
Within the Network view:
Right-click and choose Visualizer to add it.
Click the Visualizer node to open up the Visualizer Details on the right.
Choose
Image
from theSelected Visualizer
list.Connect the Dataset node output to the input of the Visualizer node.
Prediction and Ground Truth Visualizer
Additional Visualizers will be connected to the prediction and ground truth, in order to visualize the model's prediction output. Follow the steps below:
Within the Network view:
Right-click and choose Visualizer to add it.
Click the Visualizer node to open up the Visualizer Details on the right.
Choose
HorizontalBar
from theSelected Visualizer
list.Connect the last Dense layer output to the input of the Visualizer node.
Repeat the steps, and connect the second visualizer to the GroundTruth node's output.
Save Network Version
Great! Your first version is ready to be saved.
Training
Tensorleap can import trained and untrained models. In our case, the model was created from scratch and needs to be trained.
Metrics
Once training begins, you can start tracking metrics in real-time.
Add a Dashboard and Dashlets
Make sure that the model is selected from the Versions view, and add a new Dashlet.
Next, add another Line Dashlet for the accuracy. Follow all the previous steps to add it and set the Dashlet Name to Accuracy
and set the Y-Axis to metrics.Accuracy
. Do not forget turn on Split series by subset
.
Overview
As training progresses, you should see loss values declining and accuracy values increasing. When training is completed, the model achieved an accuracy of 98%.
Up Next - Model Perception Analysis
Tensorleap provides a host of innovative tools for model analysis and debugging. It tracks how each sample flows through each layer, and how each learned feature flows through the model. It also stores metrics in a big dataset to analyze the model's response to data.
We've discussed integrating and training our model. It's now time to analyze it. The next part of this tutorial will demonstrate various analyses of the model and data.
Once you are ready, proceed to Model Perception Analysis.
Last updated