Imagine a small nursery that grows a rare variety of roses. One morning, the owner notices pale circular marks on several leaves. The symptoms do not clearly match the common disease photos available online. An agricultural expert can inspect the plants, but reaching the nursery may take several days. By then, the infection might spread across the entire crop.
What if the owner could photograph a leaf and receive an early disease prediction within seconds?
Building such a system from scratch sounds exciting, but it creates a serious problem. A new deep learning model normally needs thousands or sometimes millions of labelled images. A niche plant disease may have only a few hundred usable photographs. Collecting more images, verifying every disease and training a large model can require months of work.
This is where transfer learning for plant disease detection becomes useful.

WHAT IS TRANSFER LEARNING?
Transfer learning is the process of taking a model that has already learned one task and adapting it to perform a related new task.
Think of an experienced photographer learning to identify plant diseases. The photographer may not know the disease names yet, but they already understand shapes, colours, textures, shadows and visual patterns. They do not need to relearn how vision works. They only need to connect their existing visual knowledge with new disease labels.
A pre-trained image model works in a similar way.
Models such as ResNet are commonly trained on a large image collection called ImageNet. During that training, the model learns to notice basic visual features such as edges, curves and colour changes. Its deeper layers gradually learn more meaningful patterns, including textures, object parts and complex shapes.
Those learned features can be reused for a new problem. Instead of teaching a neural network everything from the beginning, we provide it with labelled leaf images and adjust its existing knowledge. This adjustment is called fine-tuning a pre-trained model.
There are two common ways to use transfer learning. We can keep the original model layers fixed and train only the final classification layer. This method is known as feature extraction. Another option is to unlock some or all of the model’s existing layers and train them on the new dataset. This process is called fine-tuning.
The right method depends on the size of the dataset and how different the new images are from the images used during the model’s original training.
WHY NOT TRAIN A NEW MODEL FROM SCRATCH?
Suppose we want to identify three conditions in tomato leaves:
• Early blight
• Late blight
• Healthy leaf
We collect 400 verified images for each condition. That gives us 1,200 images in total. For a traditional machine-learning project, this may sound like a useful amount of data. For a deep neural network with millions of adjustable parameters, however, it is quite small.
A model trained from scratch may memorise the training photographs instead of understanding the actual disease. It might learn that early-blight images usually have a wooden background or that healthy leaves were photographed in brighter light.
Its training accuracy may look impressive, while its predictions fail on photographs taken in a real field.
With transfer learning on a small image dataset, the model does not begin with random knowledge. It already recognises useful visual structures. We mainly teach it which combination of spots, discolouration and texture belongs to each plant condition.
This can reduce training time, lower computing requirements and improve results when labelled data is limited. However, transfer learning is not magic. Poor photographs, incorrect labels and an unrealistic dataset can still produce an unreliable model.

WHY USE RESNET FOR LEAF DISEASE CLASSIFICATION?
ResNet stands for Residual Network. It was introduced by Kaiming He and fellow researchers to make very deep neural networks easier to train.
As neural networks become deeper, information and learning signals may struggle to move through every layer. ResNet addresses this problem using shortcut connections, which are also known as skip connections. A shortcut allows information to bypass one or more layers and move through the network more directly.
Imagine that you are improving a written document. Instead of rewriting every sentence from the beginning, you keep the original document and learn only the changes needed to make it better.
A residual block follows a similar idea. Rather than learning a complete new representation every time, it learns the difference required to improve the existing input.
This design allowed the original ResNet researchers to train networks containing as many as 152 layers. Their ResNet system won the 2015 ImageNet image-classification competition and later became an important foundation for computer vision projects.
For our niche plant disease detector, ResNet fine-tuning offers three practical advantages.
First, the early layers of ResNet already recognise general image patterns. These include edges, lines, colour changes and textures. Such patterns remain useful even though ImageNet was not created specifically for agricultural diseases.
Second, ResNet is available in different sizes, including ResNet18, ResNet34, ResNet50, ResNet101 and ResNet152. A beginner can start with ResNet18 because it is smaller and faster to train. A larger project can later compare it with deeper versions such as ResNet50.
Third, pre-trained ResNet models are easily available through popular deep learning frameworks. Developers do not need to design an entire neural network from the beginning. They can spend more time improving the dataset, checking predictions and solving real farming problems.
OUR REAL-WORLD DISEASE DETECTION SCENARIO
Throughout this guide, we will develop the idea of a custom plant disease detection model for a rare tomato-leaf infection.
Our sample dataset contains four classes:
• Healthy leaf
• Early blight
• Late blight
• A locally occurring fungal infection
The final system should accept a leaf photograph and return the most likely disease class along with a confidence score.
However, its real goal is not simply to achieve high accuracy inside a computer notebook. It should also work when a farmer photographs a leaf under natural sunlight, against a soil background or while other leaves appear in the same image.
This difference between laboratory accuracy and real-world reliability is where many plant disease detection projects succeed or fail.
The PlantVillage dataset contains more than 54,000 images of healthy and diseased leaves across 38 categories. It is a helpful starting point for learning and experimentation. However, many of its images were captured in controlled conditions with simple backgrounds.
Research has shown that a model may sometimes learn clues from the image background instead of learning the actual disease symptoms. For example, it may connect a particular background colour with a disease category. Such a model can perform well during testing but fail when shown photographs from a real farm.
Therefore, before writing the training code, we must solve the most important part of the project: building a clean, balanced and realistic plant disease dataset.

HOW TO PREPARE A PLANT DISEASE DATASET
A strong plant disease detection model begins with reliable images, not complicated code. If the dataset contains incorrect labels, repeated photographs or unrealistic backgrounds, even the best ResNet model will learn the wrong patterns.
Let us prepare the tomato-leaf dataset step by step.
STEP 1: COLLECT REALISTIC LEAF IMAGES
Collect photographs from different farms, plants, cameras and weather conditions. Do not photograph every leaf against the same wall or sheet of paper. The model should see the same kind of environment it will face after deployment.
Include photographs taken:
• In direct sunlight
• Under cloudy conditions
• From different angles
• At different distances
• With soil or other leaves in the background
• During early and advanced stages of infection
• Using different mobile phone cameras
Suppose all healthy leaves are photographed in a laboratory, while diseased leaves are photographed in a field. The model might learn to separate laboratory and field backgrounds instead of learning the disease symptoms.
This is known as dataset bias. The model appears intelligent, but it is following an accidental visual clue.
STEP 2: VERIFY EVERY DISEASE LABEL
A photograph should not receive a disease label based only on an online image comparison. Similar plant diseases can produce nearly identical spots, yellow areas and damaged edges.
Whenever possible, labels should be verified by a plant pathologist, agricultural expert or reliable laboratory test. If an image is unclear, place it in a separate “review required” folder instead of forcing it into a disease category.
For our custom plant disease detection model, the folder structure may look like this:
dataset
• healthy
• early_blight
• late_blight
• local_fungal_infection
Clear folder names make it easier to load the images and connect each folder with the correct class label.

STEP 3: REMOVE POOR AND REPEATED IMAGES
Before training, check the dataset for duplicate photographs, screenshots, blurred images and files that do not clearly show the leaf.
Repeated images create a hidden problem. Imagine taking ten burst-mode photographs of the same leaf. If eight images enter the training set and two enter the test set, the model may recognise that exact leaf. Its test score will look excellent, but the result will not prove that it can identify the disease on a new plant.
Therefore, all photographs of the same leaf or plant should remain in the same dataset group.
STEP 4: CREATE TRAINING, VALIDATION AND TEST SETS
The complete dataset should be divided into three parts.
The training set teaches the model. It normally contains the largest share of images.
The validation set checks the model during training. It helps us decide when to stop training and which settings are performing well.
The test set is used only after training is complete. It provides a more honest measurement of how the final model handles unseen images.
A practical starting split is:
• 70% images for training
• 15% images for validation
• 15% images for testing
This percentage is not a fixed rule. More important than the exact ratio is preventing data leakage. Images of the same plant, same photography session or same video sequence should not be spread across different sets.
The test set should also contain real field images. Testing only on clean images with plain backgrounds will not tell us whether the system is ready for farmers.
STEP 5: HANDLE UNEQUAL DISEASE CLASSES
Real datasets are rarely balanced. We may collect 1,000 healthy-leaf images but only 150 photographs of the rare fungal infection.
If this imbalance is ignored, the model may frequently predict the common class because doing so gives it a reasonable overall accuracy. The rare disease—the class we care about most—may still be missed.
We can reduce this problem by collecting more rare-disease photographs, applying careful data augmentation or giving a higher training weight to the smaller class. We should not create hundreds of nearly identical copies and assume the problem has been solved.
Accuracy must also be checked separately for every disease category.
WHAT IS DATA AUGMENTATION?
Data augmentation creates slightly modified versions of training images. A leaf photograph may be rotated, cropped, flipped or adjusted for brightness. These changes help the model understand that a disease remains the same even when the photograph is taken from another angle or under different light.
Useful augmentation for leaf disease recognition may include:
• Small rotations
• Horizontal flipping
• Random cropping
• Limited zoom
• Mild brightness and contrast changes
• Slight changes in image position
Augmentation should remain realistic. Turning a green leaf purple or hiding most of its infected region can damage the training process. The goal is to copy natural camera variation, not create impossible plants.
Augmentation should be applied only to training images. Validation and test images should remain unchanged, apart from the standard resizing and normalisation required by ResNet.

PREPARING A PRE-TRAINED RESNET MODEL
Once the dataset is ready, we can load a ResNet model with pre-trained ImageNet weights. ResNet18 is a practical starting point because it trains faster and requires less memory than deeper versions.
A standard ResNet18 model was originally built to predict 1,000 ImageNet categories. Our dataset contains only four plant conditions. Therefore, its final classification layer must be replaced with a new layer containing four outputs.
Each output represents one class:
• Healthy leaf
• Early blight
• Late blight
• Local fungal infection
At the beginning, we can freeze the earlier ResNet layers. Freezing means their learned weights will not change during the first training stage. Only the new classification layer will learn from our leaf images.
This approach allows us to test whether the existing ResNet features are already useful for the problem. It also reduces training time and lowers the risk of damaging useful pre-trained knowledge.
CHOOSING THE CORRECT IMAGE SIZE
ResNet models generally receive images in a fixed format. A common input size is 224 × 224 pixels with three colour channels: red, green and blue.
However, resizing must be handled carefully. Disease symptoms may appear as tiny spots, narrow rings or small changes in texture. If a high-resolution leaf image is reduced too aggressively, these details may disappear.
Before training the complete dataset, inspect several resized images manually. Check whether the disease marks are still visible. If important symptoms are extremely small, crop the useful leaf region before resizing or test a higher input resolution.
Images should also be normalised using the preprocessing method expected by the selected pre-trained weights. Correct preprocessing keeps the new leaf images in a format similar to the images the model saw during its original training.
TRAINING THE NEW CLASSIFICATION LAYER
The first training stage is similar to teaching an experienced visual observer four new names. The observer already understands colours, lines and textures. We are simply teaching it which learned features belong to each plant condition.
During every training cycle, also called an epoch, the model follows a simple process:
It receives a batch of leaf images.
It predicts a disease class for each image.
Its predictions are compared with the correct labels.
The error is calculated using a loss function.
The classification-layer weights are updated.
Performance is checked on the validation set.
We should save the model version that performs best on validation data rather than automatically keeping the final epoch. If training accuracy continues to increase while validation performance becomes worse, the model is probably memorising the training set.
This problem is called overfitting.
After the new classification layer learns the basic task, we can begin careful ResNet fine-tuning. Instead of unlocking the complete network at once, we can unfreeze the final residual block and train it using a smaller learning rate.
A small learning rate changes the pre-trained weights slowly. This allows the deeper ResNet features to adjust to plant textures and disease patterns without quickly erasing the useful visual knowledge learned from ImageNet.

The model is now learning what diseased leaves look like. Our next challenge is more important: finding out whether its predictions can actually be trusted.
writing{variant="standard" id="50834"}
HOW TO CHECK WHETHER THE MODEL CAN BE TRUSTED
A high accuracy score does not automatically mean that a plant disease detection model is reliable. Imagine that 80 out of every 100 test images show healthy leaves. A weak model could predict “healthy” for almost every photograph and still report high accuracy.
Precision tells us how often a disease prediction is correct. If the model predicts late blight 50 times but only 40 predictions are correct, its precision for late blight is 80%.
Recall tells us how many real disease cases the model successfully finds. If the test set contains 50 late-blight leaves and the model identifies only 35, its recall is 70%.
The F1-score creates a balance between precision and recall. It is especially helpful when one disease class contains far fewer images than the than the others.
In a crop disease detection system system, recall can be extremely important. Missing an infected plant may allow the disease to spread. However, very low precision can also cause problems because farmers, recall can be extremely important. Missing an infected plant may allow the disease to spread. However, very low precision can also cause problems because farmers may may receive too many false warnings.
The final balance should be selected according to the real use of the model. receive too many false warnings.

USE A CONFUSION MATRIX TO FIND HIDDEN ERRORS
A confusion matrix shows which classes the model is mixing mixing up.
For example, the model may correctly identify most healthy leaves but repeatedly confuse early blight most healthy leaves but repeatedly confuse early bl with the local fungal infection. Thisight with the local fungal infection. This result tells us something useful that overall accuracy result tells us something useful that overall accuracy cannot explain.
We can then inspect We can then inspect the incorrect predictions the incorrect predictions and ask:
• Do both diseases produce diseases produce similar brown spots?
similar brown spots?
• Are the images Are the images wrongly labelled?
wrongly labelled?
• Is one disease disease class too small?
class too small?
• Are important the important symptoms difficult to see symptoms difficult to see after resizing?
after resizing?
• Is the model focusing on the background instead of the leaf?
Every wrong prediction has a story. Looking at these mistakes often improves the model more than simply training it for additional epochs.
Grad-CAM or a similar visual explanation method can also highlight the image area that influenced a ResNet prediction. If the highlighted regionAM or a similar visual explanation method can also highlight the image area that influenced a ResNet prediction. If the highlighted region covers the infected spots, the model may be using meaningful evidence. covers the infected spots, the model may be using meaningful evidence. If it focuses If it focuses on a hand, background or on a hand, background or camera watermark camera watermark, we have discovered a serious weakness.
FIELD TESTING THE RES, we have discovered a serious weakness.
FIELD TESTING THE RESNETNET MODEL
After the model performs well on the test set the model performs well on the test set,, it should be evaluated on a separate collection of field it should be evaluated on a separate collection of field photographs photographs. These images should come. These images should come from locations from locations,, farms farms and and mobile mobile phones that were phones that were not represented during not represented during training.
A worker photographs 100 plants during a normal working day. Some images contain shadows, folded leaves, soil, water drops and and partially hidden symptoms. partially hidden symptoms An agricultural expert independently checks. An agricultural expert independently checks the plants and records the plants and records the correct conditions.
The model model’s’s predictions predictions are then compared are then compared with the expert’s findings.
field test may produce a may produce a lower score than the original test set. That is not necessarily a failure. It provides a more honest picture of how the system behaves outside controlled conditions.
If performance drops sharply, collect lower score than the original test set. That is not necessarily a failure. It provides a more honest picture of how the system behaves outside controlled conditions.
Collect, verify, train, test, review errors and examples of the new conditions, verify their labels and add suitable images to the next training cycle. This creates a practical improvement loop:

DO NOT TREAT CONFIDENCE AS CERTAINTY
An image classification model usually returns a probability or confidence score for each class. For example:
Late blight: 72%
Early blight: 18%
Local fungal infection: 7%
Healthy leaf: 3%
The 72% score does not mean there is a guaranteed 72% chance that the plant has late blight. It shows how strongly the model prefers that class based on what it learned.
A high score can still be wrong, especially when the model receives an unfamiliar image. A damaged leaf, insect based on what it learned.
A high score can still be wrong, especially when the model receives an unfamiliar image. A damaged leaf, insect bite bite or or disease disease that was never included in training may that was never included in training may be be forced into one of the known categories.
A safer system should include an “uncertain” result. If the confidence is below a carefullyuncertain” result. If the confidence is below a carefully tested limit, the application can tested limit, the application can ask the ask the user to take another photograph or contact an agricultural expert.
The model should support disease screening, not replace professional diagnosis.
DEPLOYING THE MODEL IN A REAL APPLICATION
Once testing is complete, the fine-tuned ResNet model can be connected to a web or mobile application.
A simple user flow could work like this:
A farmer photographs the affected leaf.
The application checks whether the image is clear.
The image is resized and application checks whether the image is clear.
ResNet predicts the most likely disease class.
The result, confidence level and next step appear on normalised.
If the application must work without an internet. ResNet18 may connection, ResNet18 may be be easier easier to run on a mobile device than a to run on a mobile device than a much deeper model. Model compression much deeper model. Model, quantisation compression, quantisation or a lightweight architecture or a lightweight architecture can reduce its size can reduce its size further.
The interface should also explain that the result is an early further.
The interface should also explain that the result is an early prediction prediction. It should not directly recommend a pesticide without considering crop type, disease stage, local rules and expert advice.
COMMON MISTAKES TO AVOID
One common mistake is placing images of the same plant in both training and test sets. This creates data leakage and produces misleading results.
Another mistake is using accuracy as the only performance measure. Precision, recall, F1-score and class-level errors provide a clearer picture.
Developers may also fine-tune every ResNet layer too early. With a small dataset,ers may also fine-tune every ResNet layer too early. With a small dataset, this can erase useful pre-trained features and increase overfitting this can erase useful pre-trained features and increase overfitting.
Finally, a model should not a model should not be be considered ready simply because it performs well on PlantVillage or another clean dataset. Real farms considered ready simply because it performs well on PlantVillage or another clean dataset. Real farms contain shadows, mixed backgrounds contain shadows, mixed backgrounds, damaged leaves and previously unseen diseases, damaged leaves and previously unseen diseases.

Final Thoughts
Transfer learning gives small agricultural projects a practical starting point. Instead of collecting millions of collecting millions of images and training a neural networks
from zero images and training a neural network from zero, we can reuse, we can reuse the the visual knowledge of visual knowledge of a pre-trained Res a pre-trained ResNet modelNet model..
However, the model architecture architecture is only one part of the solution. is only one part of the solution. Reliable labels, realistic photographs, careful dataset splitting and honest field-testing matter just as much.
The best plant disease detection using deep learning is not the system with the most impressive laboratory accuracy. It is the one that knows its limits, handles real field images the system with the most impressive laboratory accuracy. It is the one that knows its limits, handles and guides uncertain cases toward human expertise..
When used with transfer learning is used with that that level of care level of care, a small collection of leaf, a small collection of photographs can grow into a useful early-warning tool leaf photographs can grow into a useful early-warning tool—one that helps farmers notice problems sooner and protect crops before the damage spreads.
FREQUENTLY ASKED QUESTIONS
What is transfer learning in plant disease detection?
Transfer learning is a method in which a model that has already learned general image patterns is adapted for plant disease detection. A pre-trained model understands features such as colours, edges, shapes and textures. We fine-tune this existing knowledge using labelled images of healthy and diseased leaves.
Why is ResNet suitable for leaf disease classification?
ResNet uses shortcut connections that help a deep neural network learn effectively. Its pre-trained versions already recognise useful visual patterns, making ResNet fine-tuning helpful when the plant disease dataset is small. ResNet18 is a practical starting option because it is faster and lighter than deeper ResNet models.
How many images are required for transfer learning?
There is no fixed number that works for every project. A few hundred verified images for each disease class can provide a useful starting point. However, image quality and variety are more important than the total number. The dataset should contain different plants, disease stages, cameras, backgrounds, angles and lighting conditions.
Can ResNet detect a rare plant disease?
Yes, ResNet can be fine-tuned to recognise a rare plant disease if enough correctly labelled photographs are available. The images should show the disease at different stages and under real field conditions. Predictions for rare diseases should still be checked by an agricultural expert.
What is the difference between feature extraction and fine-tuning?
In feature extraction, the original layers of the pre-trained model remain frozen, and only the new classification layer is trained. During fine-tuning, some or all of the pre-trained layers are unlocked and adjusted using the new plant images. Feature extraction is usually a safer starting point when the dataset is small.
Why can a model perform well during testing but fail on a farm?
The model may have learned backgrounds, lighting patterns or repeated images instead of actual disease symptoms. This often happens when training and test images come from the same controlled environment. A reliable model must also be tested using photographs from new farms, cameras and weather conditions.
What is data augmentation in plant disease detection?
Data augmentation creates realistic variations of training images by applying small rotations, flips, crops, zoom and brightness adjustments. It helps the model recognise the same disease under different camera and lighting conditions. Augmentation should remain realistic and should only be applied to training images.
Is a model’s confidence score always reliable?
No. A confidence score only shows how strongly the model prefers one available class. A high-confidence prediction can still be incorrect, especially when the image contains an unseen disease, insect damage or poor lighting. Uncertain cases should be reviewed by an agricultural expert.
Can a plant disease detection model work without the internet?
Yes. A smaller model such as ResNet18 can be optimised for use on a mobile device. Techniques such as model compression and quantisation can reduce its size. The final performance will depend on the mobile device, application design and model complexity.
Can AI replace an agricultural expert?
No. A plant disease detection model should be treated as an early screening tool. It can help farmers notice possible symptoms quickly, but final diagnosis and treatment decisions should include expert advice, crop conditions, laboratory testing and local agricultural guidance.
Do you want to know about Batch Normalization & Dropout