In this chapter, you will build your first computer vision model for image classification. You will learn how to load and prepare a dataset, choose and set up a model, and train it using epochs, a loss function, an optimizer, and a training loop. You will then learn how transfer learning allows you to start with a pretrained vision model and adapt it to your own classification task. By the end, you will understand the basic workflow for training a vision model and be able to apply it to a new image classification problem.
Training a neural network is somewhat like teaching the human brain.
Imagine teaching a child to recognize a cat. You show the child many pictures of cats and say, “This is a cat.” At first, the child makes mistakes, but with more examples and feedback, the brain gradually learns which features—ears, eyes, shape, fur—help identify a cat.
A neural network learns in a similar way. We give it many training examples, it makes a prediction, and we compare that prediction with the correct answer. The error (loss) tells the network how wrong it was, and an optimization process adjusts its internal weights, somewhat like the brain strengthening or weakening connections between neurons.
So, in simple terms:
Examples → Prediction → Error/Feedback → Adjust connections ( what we call weights) → Learn → Better predictions
The analogy is not exact—the biological brain and artificial neural networks work very differently—but it is a useful way to understand the basic idea of learning from experience and feedback.
Practice 3: You will find a streamlit based chapter at https://github.com/jhilikb/UCS668
Prerequisite: Make sure that you have the Train_Models folder in your course folder UCS668.
Start your python environment (say ucs668) that you set up (in Lab0) for the course using source ucs668/bin/activate (on your terminal if you use Linux/Mac) or using .\ucs668\Scripts\Activate.ps1 (on your powershell if using windows). In both cases you should be in the folder where you created the environment
cd Train_Models
unzip "Flower Classification Dataset.zip"
streamlit run mymodels.py
You will see the chapter start on your browser. In your browser, you can now explore the example tasks and understand how to solve them.
GPT guide for more practice:-
https://chatgpt.com/share/6a7d3df5-2474-83e8-ad55-93eb85f40894
Common Confusions form
https://forms.gle/4DgQFUZBmSDSyC7r5
Lab 3: In this lab we will start training a few networks. You will be able to access a sample notebook at https://colab.research.google.com/drive/17vyDwrH_60Ztx9ZjBGt54kW2waB8bmEP?usp=sharing
In the notebook you learn about "loading images with different libraries" , "different deep learning frameworks" , "loading data in bulk" , "model" , "training testing loop"
You will not make any changes in the "training testing loop" other than the number of epochs.
Task 1: Road crack classification problem. Remember you explored road damage datasets, pick the most effective one and complete the following subtasks:-
a) Load the dataset , remember if it does not have well defined train/test folders you will have to use the splitting part of the code instead of the current part. Also dont forget to put the correct folder names.
b) Use training from scratch. You have to change the number of classes in the last layer. You may also make other changes in the network.
c) Change number of epochs and observe the result.
d) Now use transfer learning with i)vgg ii)resnet-18 and record the results. In each case you can print the model to see what you have to change in the last layer. Record the results.
e) Perform finetuning to the entire network for 2-3 epochs. Record the results.
Submit your report at https://classroom.google.com/c/ODcyMDQ0MTU1MzAw/a/ODc0NzEzNTA2NTI1/details