Check out a free preview of the full Machine Learning in JavaScript with TensorFlow.js course

The "Model Summary" Lesson is part of the full, Machine Learning in JavaScript with TensorFlow.js course featured in this preview video. Here's what you'd learn in this lesson:

Charlie demonstrates how the `model.summary()` method can provide additional details and visualize the training process. Layer data is displayed, and the input and output shapes can be compared.


Transcript from the "Model Summary" Lesson

>> Okay, so hopefully at this point, if you've been following along, you should have a machine learning model that you created on your own. So congrats for creating your first custom machine learning model. Even if the accuracy is about 0.5 and it's not the best right now, you still created a custom measuring model with your custom data set as well.

So first of all, pat on the back to yourself for doing that. And as we were talking before, there's a lot of tweaks that you can do. You can generate a lot of new images, or you can add layers or change them. And there's not really, as you can see, machine learning models, it's not really a pure function where, if you give it the same input, it will give you the same output.

It seems to be changing and the weights are updated and things like that. So it's kind of hard to be able to get the same kind of output out of the model. But one thing that is for sure is that we only created for the images of each type of each label.

And that in general, if you start to talk to you people who do machine learning day to day and you told them that you only have one images that are probably tell you well, you need a lot more to be able to find patterns in these images. So if you're using open source models that've been created on at least thousands of images, if not millions.

But there's one thing that I forgot to show you that I wanted to add here, is if you go to the train drawings.js file. There's just also a little function that you can add here that is called model.summary. And what this does is just it's going to print to the terminal the different layers of your model and the input shape and output shape.

And just kind of gives you an idea, and I thought it was interesting. It's not necessary at all. As you can see, when we were running things before, it was running fine and you could see the different training stages with the epochs. But calling model.summary, if we go to the terminal and we rerun node train drawings, it will output this table above here.

That kind of tells you, you can see the different layers of our model. So our first layer is a Conv2D, then we have a max_pooling2d, then we flatten. And then we have two dense layers. And here we can see, over time, the first inputs, kind of structure that we passed, it was like 28, 28, 4.

And you can see that the output of that layer becomes 26, 26, 32. And here, 32, I believe it's the filters that we passed in. And 26,26, I forgot why it just removes 2. But here, for example, in our MaxPooling2D, the input shape is the same as the output of the previous layer.

And you can see here that we end up with 13,13. And because I believe that our MaxPooling2D was an area of 2 and 2, so I think it just divides the input by 2. And here again, now we move on to our Flatten layer. And you can see here you have an array within an array and what comes out of it is a single array.

And this 5408 is actually 13 by 13 by 32. So this is what flatten does. It takes some kinda this multidimensional array, it flattened it into single one. And then here in the dense layer for some reason it still actually has an array within an array. But the format here is the 5,408 and it comes out with 10.

And, again, 10 is the number that we use for the units. And, again, units is the kind of the shape of your output or the number of your output. And thenin our final layer, because we have two classes, if you remember, we have a final dense layer that takes that as an input, and we have an output just the number 2 because the center number of our classes.

So when you call the model.summary, it kind of gives you a bit of a visualization as a table of the different steps. So sometimes you could also maybe use this to kinda give you an idea of maybe certain things that you should change. But I thought that it was just a nice thing to mention to more of.

Have a visualization of what's going on in your training process.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now