KwickAcademy Artificial Intelligence · 8 min · free
Deep Learning Hands-on with TensorFlow and Keras
TensorFlow is Google's deep learning library and Keras is its easy API. Every project: load, build, compile, fit, evaluate, predict.
Follows the syllabus of: CBSE Class 12 Artificial Intelligence (843)
On screen in this lesson
TensorFlow and Keras
| Tool | What it is | Note |
|---|---|---|
| TensorFlow | deep learning tool | Google, open source |
| Keras | easy layer API | inside TensorFlow |
| Tensor | array of numbers | the data type |
Why use Keras?
| Build a network in a few readable lines |
| Ready-made layers, optimisers and datasets |
| Same code runs on a laptop or a GPU |
| Free to use in Google Colab, nothing to install |
Pause and predict
| Why does the output layer have exactly 10 neurons? |
| Answer: one neuron for each digit, 0 to 9 |
| The biggest probability is the prediction |
| For 26 letters of the alphabet, use 26 neurons |
Counting the weights
| Layer | Calculation | Parameters |
|---|---|---|
| Flatten | no weights | 0 |
| Dense 64 | 784 x 64 + 64 | 50,240 |
| Dense 10 | 64 x 10 + 10 | 650 |
| Total | 50,240 + 650 | 50,890 |
Reading the accuracy
| Train | Test | Meaning |
|---|---|---|
| 98% | 97% | good, generalises |
| 99% | 85% | overfitting |
| 70% | 69% | underfitting |
Where to go next
| CNNs: add Conv2D layers for better image accuracy |
| Teachable Machine: train models with no code |
| Kaggle: free datasets and practice notebooks |
| LiteRT, earlier TensorFlow Lite: run models on phones |
Quick answers
Why does the output layer have 10 neurons?
One for each digit, 0 to 9.
Train 99%, test 85%: what is it?
Overfitting.
KwickClips from this lesson
Short clips, one idea each. Good for revision the night before.
Who makes TensorFlow?40 sec
What does Flatten do?40 sec
Train 99%, test 85%: what is it?40 sec
What improves image accuracy?41 secThe full lesson, in text
Hello students, welcome to Kwickprep. Can you teach a computer to read handwritten digits in about fifteen lines of Python? Yes, you can. Today we meet TensorFlow and Keras, build a small neural network, train it, check its accuracy, and plan where to go next.
Let us meet the two tools first. TensorFlow is a free, open source library from Google for building and training deep learning models. Keras is a simpler interface, called an API, that lets us build a network layer by layer, and it comes inside TensorFlow. The name TensorFlow comes from tensors, which are just multi dimensional arrays of numbers, like a grid of pixel values.
Why do beginners and experts both use Keras? You can build a network in a few lines that read almost like English. It gives ready made layers, optimisers and even practice datasets. The same code runs on a normal laptop or on a GPU, a graphics chip that trains models much faster. And Google Colab already has TensorFlow installed.
Every Keras project follows the same steps. First, we load and prepare the data. Second, we build the model by stacking layers. Third, we compile the model, which means choosing how it will learn. Fourth, we train it with the fit function. Fifth, we test it on data it has never seen, using evaluate. Finally, we use it to predict new data.
We use MNIST, a famous dataset of handwritten digits from zero to nine. Each image is twenty eight by twenty eight pixels in greyscale. The variable d holds the dataset, and load data gives sixty thousand training images and ten thousand test images. Here x t r and y t r are the training images and labels. And x t e and y t e are the test ones. We divide pixels by two hundred fifty five, so every value lies between zero and one, which helps training.
Now we build the network. Sequential means the layers are stacked one after another. The input is a twenty eight by twenty eight image. Flatten turns this grid into one long row of seven hundred eighty four numbers. A Dense layer connects every input to every neuron, so our hidden layer has sixty four neurons. The second value, relu, is its activation. The output layer has ten neurons with softmax, which turns the outputs into probabilities that add up to one.
Pause and predict before we move on. Why does the output layer have exactly ten neurons? Because there are ten possible answers, one neuron for each digit from zero to nine. The neuron with the highest probability is the model's prediction. So if you wanted to recognise the twenty six letters of the English alphabet, you would use twenty six output neurons.
Keras can show a model summary, and it counts the parameters, which are all the weights and biases. Flatten only reshapes the data, so it has no parameters. The hidden layer has seven hundred eighty four times sixty four weights. Add sixty four biases, and we get fifty thousand two hundred forty. The output layer has sixty four times ten weights plus ten biases, which is six hundred fifty. So the total is fifty thousand eight hundred ninety numbers to learn.
Compiling sets three choices for learning. The loss function measures how wrong the predictions are. Sparse categorical cross entropy suits labels that are simple numbers, like three or seven. We store its long name in l f. The optimizer decides how to change the weights, and Adam is a popular, reliable choice. Metrics are what we want to watch, and here it is accuracy. Summary prints the table of parameters we just calculated.
Training takes just one statement. Fit shows the training images and labels to the network again and again. One epoch means one full pass through all the training images, so five epochs means five passes. Validation split of zero point one keeps ten percent of the training data aside, to check progress after each epoch. On Colab, this takes about a minute, and you see the loss go down and the accuracy go up.
Now the real test. Evaluate checks the model on the ten thousand test images, which it has never seen during training. It returns the loss and the accuracy. Accuracy means the fraction of images predicted correctly. A small network like ours usually reaches about ninety seven percent. Your exact number will differ slightly, because training starts from random weights.
Always compare training accuracy with test accuracy. If both are high and close, the model has learned the general pattern, and that is what we want. If training accuracy is much higher than test accuracy, the model has memorised the training data, which is called overfitting. If both are low, the model is too simple or trained too little, which is called underfitting.
Finally, let us use the model. Predict takes the first test image and returns ten probabilities, one for each digit. Argmax from NumPy gives the position of the biggest probability, and that position is the predicted digit. We can compare it with y t e zero, the true label. For the first test image in MNIST, the true answer is seven, and a trained model almost always predicts seven.
Here are four good next steps for your learning and your project work. Add Conv2D layers to build a convolutional network, which usually pushes MNIST accuracy above ninety nine percent. Try Google's Teachable Machine, which trains image or sound models in the browser without code. Use Kaggle for free datasets and example notebooks. And learn LiteRT, earlier called TensorFlow Lite, to run your model inside a mobile app.
Here are a few project ideas using the same steps. Train a model to recognise hand signs for numbers from photos. Sort leaf photos into healthy and diseased, which can help farmers. Classify short product reviews as positive or negative. Whatever you build, always keep separate test data, because a model is only as good as its accuracy on new data.
Let us revise what we learned today. TensorFlow is Google's open source deep learning library, and Keras is its easy API. Every project follows load, build, compile, fit, evaluate and predict. We used Dense layers with ReLU, and a softmax output with one neuron per class. Always compare training and test accuracy to spot overfitting. Next, explore CNNs, Teachable Machine, Kaggle and LiteRT.
Courses that teach this
| Course | Unit |
|---|---|
| CBSE Class 12 Artificial Intelligence (843) | Understanding Neural Networks |
Voice-over in this lesson is AI-generated. The script is written and checked by Kajal Ma'am. Boards can revise a syllabus mid-year, so confirm anything you plan around against the official board circular. Keep your passwords, OTPs and ID numbers to yourself — we never ask for them. To reach Kajal Ma'am, use the WhatsApp button; sharing your number there is how we call you back.
Free to watch, no sign-up. Live classes with Kajal Ma'am are the paid course; these lessons stay free either way.

