How to Build an Image Classification Model with Pre-Trained Networks
A pre-trained network lets you build an image classifier from a few thousand photos instead of millions. Here is how transfer learning works and how to train one.
On this page
Short answer
An image classification model built with a pre-trained network starts from a neural network that has already learned to recognise shapes, textures and objects from a large set of images. You keep most of that knowledge and train only the final layers on your own labelled photos, which is why a few thousand images are often enough.
What is image classification with a pre-trained network?
Image classification with a pre-trained network is a way to teach a computer to sort photos into categories by starting from a neural network that has already learned to recognise shapes, textures and objects from a large set of images. Instead of training from nothing, you reuse what the network already knows and teach it only the categories you need.
A classifier answers one question about each photo: which category does this belong to? That could be a product type, a plant disease, a defect on a production line, or a type of document. The network looks at the pixels, finds patterns it has seen before, and gives a score for each category. The highest score wins. The basics of the field are covered in what computer vision is.
The reason pre-trained networks matter is data. Training a network from scratch needs millions of labelled photos, which most teams do not have. A pre-trained network has already done the hard part on a large public dataset, so your own photos only need to teach it the last step: the difference between your categories.
How does transfer learning work?
Transfer learning is the name for reusing a trained network on a new task. A neural network learns in layers: early layers find edges and textures, middle layers find shapes and parts, and late layers combine those into the categories it was trained on. Those early and middle layers are useful for almost any image task, so you keep them and replace only the ending.
| Approach | What changes | When to use it |
|---|---|---|
| Feature extraction | Only the final layer is trained | Few images, similar task |
| Fine-tuning | Final layers are retrained slowly | More images, different task |
| Train from scratch | Every layer is trained | Huge dataset, unusual images |
Feature extraction is the fastest route. You freeze the pre-trained layers, use them to turn each photo into a list of features, and train a small classifier on those features. It works well when your photos look like the ones the network was trained on.
Fine-tuning goes further. After the new final layer works, you unfreeze the last few layers and train them gently, with a small learning rate, so the network adjusts its features to your photos without forgetting what it learned. It needs more images and more care, but it usually gives better results when your categories differ from the original ones.
Which pre-trained model should you start with?
Start with a model that fits where the classifier will run and how much data you have. A model that runs on a phone has different needs from one that runs on a server. The table below compares four well-known starting points that teams reach for first. For the wider build, see how to implement computer vision.
| Model | Size and speed | Best for |
|---|---|---|
| MobileNet | Small and fast, built for phones | On-device sorting and scanning |
| ResNet | Medium size, a common baseline | A first model for most tasks |
| EfficientNet | Balanced size and accuracy | Server models where accuracy matters |
| Vision Transformer | Large, needs more data | Tasks with plenty of labelled images |
MobileNet is the usual choice when the classifier must run on a phone or a small device. It was designed to be small and fast, so it trades some accuracy for speed. If your app sorts photos on the device itself, start here.
ResNet is the safe default for a first server-side model. It is widely used, well understood, and easy to find examples for. EfficientNet is a good next step when you need more accuracy and can afford a larger model. Vision transformers are powerful but need more labelled images before they beat the simpler options, so leave them until the basics work.
How do you prepare your image data?
A classifier is only as good as its labelled photos, so data preparation is where most of the work goes. Start by collecting photos that look like the ones the model will see in use, not studio shots if the real photos come from a phone camera in a warehouse.
Split the photos into three sets: training, validation and testing. The training set teaches the model. The validation set tells you whether changes help while you work. The test set stays untouched until the end, so the final score is honest. A common split is 70 percent for training and 15 percent each for validation and testing.
Label carefully and check the labels twice. A wrong label teaches the model the wrong thing, and a few wrong labels in a small dataset can cost more accuracy than a better model would gain. Balance the categories too: if one category has ten times more photos than another, the model learns to guess the big category and ignore the small one.
Augmentation stretches a small dataset further. Rotating, cropping and changing the brightness of a photo creates new training examples without new labelling. Use changes that match real conditions — a product photo may be tilted or dimly lit, but it will not be upside down.
How do you train the model in six steps?
Training follows a fixed sequence. Each step is simple on its own, and skipping one usually shows up later as a model that looks good in training and fails on new photos.
- Collect and label your photos. Gather images from the real setting and label each one with its category.
- Split the data. Keep 70 percent for training, 15 percent for validation and 15 percent for a final test.
- Pick a pre-trained base model. Choose one that fits your device and your data, such as MobileNet for phones.
- Replace the final layer. Swap the old categories for yours and train only the new layer first.
- Fine-tune the last layers. Unfreeze a few layers and train them gently with a small learning rate.
- Evaluate on the test set. Check accuracy per category and fix the worst confusions before shipping.
Keep notes at each step: which base model, which split, which settings. When the model misbehaves, those notes are what let you find the cause instead of guessing.
How do you measure whether the model is good enough?
Overall accuracy is a start, but it hides the important detail. A model that is right 9 times in 10 sounds good until you learn it never recognises the rarest category. Measure per category, not just overall. The wider field is explained in what machine learning is.
A confusion matrix shows which categories the model mixes up. Read it as a table: rows are the true category, columns are the predicted category, and the numbers off the diagonal are the mistakes. If two categories are often confused, the fix is usually more photos of those two, or clearer labels between them.
Test on photos the model has never seen, taken in the real setting. A model trained on clean studio photos and tested on the same kind of photos can look perfect and still fail on the first real photo. The test set should come from the same place the model will work.
Set a target before you train, tied to what the mistakes cost. Sorting product photos for a shop can tolerate a few errors. Flagging a defect on a production line cannot. The target tells you when to stop tuning and start using the model.
Example (hypothetical): sorting product photos for a small shop
Example (hypothetical): a small online shop has 4,000 product photos in 8 categories, from shoes to bags, and staff sort them by hand. The team wants a classifier that puts each new photo in the right category before it is listed.
They split the photos into 2,800 for training, 600 for validation and 600 for testing. They start with a pre-trained ResNet, replace the final layer, and train it on the 2,800 photos. After fine-tuning the last layers, the model scores 9 in 10 on the test set — 540 of 600 photos right.
The mistakes are not random. Most are between two similar categories: sandals and open shoes, which share straps and soles. The team adds 200 more photos of those two categories and retrains. The score rises to 19 in 20 on the test set, and the shop starts using the model with a human check on low-confidence photos.
What are the common mistakes?
The most common mistakes in image classification are training on photos that do not match real use, trusting one overall score, and fine-tuning too aggressively.
- Training on clean photos only. If real photos are dim or tilted, the training set must include them.
- Testing on the training data. A score on photos the model has seen says nothing about new photos.
- Fine-tuning everything at once. Unfreezing all layers with a high learning rate destroys what the network learned.
- Ignoring the small categories. A model that never predicts a rare category still looks accurate overall.
- Skipping the confusion matrix. The pattern of mistakes tells you what to fix; the overall score does not.
- Shipping without a human check. Low-confidence predictions need a person until the model proves itself.
Key takeaways
- A pre-trained network lets you build a classifier from a few thousand photos, not millions
- Feature extraction is the fastest start; fine-tuning adds accuracy when you have more data
- Split photos into training, validation and test sets, and keep the test set untouched
- Measure accuracy per category with a confusion matrix, not just one overall score
- Match the training photos to the real setting, or the model will fail on its first real photo
Frequently asked questions
What is transfer learning in image classification?
Transfer learning means reusing a neural network trained on a large set of images for a new task. You keep the layers that learned shapes and textures and train only the final layers on your own labelled photos, so a few thousand images are often enough to build a working classifier.
How many images do I need to train a classifier?
It depends on the number of categories and how similar they are, but a few hundred labelled photos per category is a common starting point with a pre-trained network. Similar categories need more photos, and the confusion matrix will show you which ones.
Should I use feature extraction or fine-tuning?
Start with feature extraction: freeze the pre-trained layers and train only the final layer. It is fast and works well with little data. Move to fine-tuning, retraining the last layers gently, when you have more images and need extra accuracy.
Which pre-trained model is best for beginners?
ResNet is a safe default for server-side work because it is widely used and well documented. MobileNet is the better choice when the classifier must run on a phone. Pick the model that fits where it will run, not the newest one.
What is a confusion matrix?
A confusion matrix is a table that shows which categories a model mixes up. Rows are the true category and columns are the predicted category, so numbers off the diagonal are mistakes. It shows whether the errors cluster between two categories, which tells you where to add photos.
Can I train an image classifier without a GPU?
Yes, for small datasets and feature extraction, a normal computer is enough because the heavy learning is already done. Fine-tuning a large model on many photos is faster on a GPU, and cloud GPU time is usually rented by the hour when you need it.