Climate-Resilient Crops · Answer Model

Deep Learning on Leaf Images: Answer Model

This is the answered version of the Deep Learning on Leaf Images practical. Every ❓ question is followed by a worked model answer (green box). All the interactive steps still work, so you can keep training models while you read, and the self-test quiz at the end is unchanged.

0 Teaching a computer to look at a leaf

A grower walking through a tomato greenhouse can spot a sick plant at a glance. Doing that at the scale of a whole breeding programme, thousands of plants, several times per season, is a different problem. This is where image-based phenotyping comes in: a camera on a drone, a robot or a phone takes the pictures, and a model decides which leaves look diseased.

In this practical you will train such a model yourself. It runs in your browser, on real photographs of tomato leaves. But the real lesson is not "how do I train a model". That turns out to be the easy part, about ten lines of code. The lesson is how do I find out whether I should trust it. You will meet a model with 90% accuracy that is completely worthless, and a model that learns the wrong thing so convincingly that only careful evaluation reveals it.

How this differs from last week's mechanistic model

In the mechanistic modelling practical you simulated a gene regulatory network. There, we supplied the biology: "ABA activates ABF2", "ANAC019 represses ICS1". Those rules were the input, written down by researchers after years of experiments, and the computer only worked out their consequences over time.

Deep learning turns this around completely. Nobody tells the model what a diseased leaf looks like. Nobody writes down "brown lesions with a yellow halo mean Septoria leaf spot". Instead we hand over a pile of photographs, each labelled healthy or infected, and the model works out the rules itself by looking for whatever distinguishes one pile from the other.

The trade-off, and the theme of this practical. A mechanistic model can only ever be as right as the biology you put into it, but you can read it, argue with it, and point at the step you disagree with. A deep learning model can pick up patterns nobody thought to encode, and it needs no theory at all, but you cannot look inside and see what it decided to pay attention to. It might have learned the disease. It might have learned something else entirely that happened to come along with the disease in your photos. Keep that possibility in mind; you will run into it in step 7.
❓ Questions
  • Name one research question about plant resilience where you would rather build a mechanistic model, and one where you would rather train a model on data. What makes the difference?
  • The model you are about to train never receives any information about tomato biology. Is that a strength or a weakness? Argue both sides.
✅ Answer
  • Mechanistic vs. data-driven. A question like "how does a longer drought shift the trade-off between drought tolerance and pathogen defence?" calls for a mechanistic model: you are asking why, you already have regulatory knowledge to encode, and you want to reason about interventions you have never tried. A question like "which of these 40,000 field photographs show disease?" calls for a data-driven model: nobody can write the rule down, but labelled examples are cheap. The deciding factors are whether you have mechanism you trust or data you trust, and whether you need an explanation or a decision.
  • Both at once. It is a strength because no theory is required, so it works in areas where our understanding is incomplete, and it can pick up subtle cues a human could never put into words. It is a weakness because the model has no notion of what is biologically relevant: it cannot tell a causal cue (a lesion) from an incidental one (the lighting, the background, the camera). It cannot explain itself, cannot be checked against known biology, and will apply a nonsensical rule with complete confidence. Both statements are true simultaneously, which is what the rest of this practical is about.

1 The data, and what the model actually sees

We use the PlantVillage dataset: photographs of single tomato leaves against a grey background, each one labelled by a plant pathologist. There is one healthy category and nine disease categories: bacterial spot, early blight, late blight, leaf mold, Septoria leaf spot, spider mites, target spot, yellow leaf curl virus and mosaic virus.

We are going to group all nine diseases together into a single infected class, so the model has to answer one binary question: healthy, or not? We could equally well have trained it to name the specific disease. That is a nine-way problem, and a harder one.

label 0, healthy label 1, infected

Every image has been shrunk to 64 × 64 pixels, which is the size the model works with.

A photograph is only numbers

This is the single most important idea in this section, and it is worth slowing down for. The model has no eyes. It never sees a leaf, a lesion or a colour. What arrives at its input is a grid of numbers, and nothing else.

Each of the 64 × 64 pixels stores three numbers: how much red, how much green and how much blue that pixel contains. A camera records those as whole numbers from 0 to 255, and before feeding them to the model we divide by 255 so everything sits between 0 and 1.

Hover over the leaf below. The panel on the right shows you the actual numbers stored in the small square you are pointing at. This is, quite literally, the model's entire view of the world.

Move your mouse over the leaf. The white square marks the 6×6 patch shown on the right.

Put together: one leaf photo is 64 × 64 × 3 = 12,288 numbers. That is what a single training example is. Everything the model ever learns about tomato disease, it has to extract from patterns in lists of 12,288 numbers, paired with a label that says 0 or 1.
❓ Questions
  • What do these numbers represent exactly? Explain what a single number in this grid means, and what the three numbers per pixel are for.
  • The original photographs are far larger than 64 × 64. What do we lose by shrinking them, and why might we do it anyway?
  • All of these photos were taken against the same plain grey background under similar lighting. Is that helpful or harmful for the model we are about to build?
✅ Answer
  • What the numbers are. Each individual number is the intensity of one colour channel at one pixel position. There are three per pixel because any colour can be reconstructed by mixing red, green and blue light, so the camera records how much of each is present. Cameras store these as whole numbers from 0 (none) to 255 (maximum); we divide by 255 so every input sits between 0 and 1, a range in which neural networks train much more stably. One leaf is therefore 64 × 64 × 3 = 12,288 numbers, plus a single label of 0 or 1.
  • What shrinking costs. We throw away fine detail: small or early lesions, spore structures, fine vein texture, anything smaller than roughly a pixel at the new size. We do it because compute and memory scale with the number of pixels, and because fewer inputs means fewer things the model can latch onto, which matters a lot when you only have a few hundred training images. It is a trade-off: too small and the symptom itself disappears. At 64 × 64 the larger blotches and colour changes still survive.
  • The uniform background: both. Helpful, because it removes a large source of irrelevant variation and lets the model concentrate on the leaf. Harmful, because it is unrealistically easy, a model trained on studio photographs against grey card has never seen soil, neighbouring leaves, shadows or direct sunlight, and will very likely fall over on a real field photo. It also means anything systematic about the setup rather than the leaf becomes available as a shortcut, which is precisely the trap in step 7.

2 Splitting the data: train and test

Before we train anything, we have to hold some data back. This is one of the most important habits in the whole of machine learning, so it is worth being precise about why.

A model that has already seen a photo can score well on it simply by having memorised it. Memorising tells you nothing about the next leaf, and the next leaf is the entire point: you want a model that works on plants it has never encountered. So we cut the dataset in two. The model learns from the training set, and is judged on the test set (also called the validation set), which it never learns from. Any number you quote about a model's performance should come from data it did not train on.

Below you control how big each half is. Watch what the split does to the number of images the model gets to learn from, and to the number of images your performance estimate is based on.

Notice the tension. Give more data to training and the model has more to learn from, but your test set shrinks and your estimate of how good it is becomes noisier. Give more to testing and you get a more reliable estimate of a weaker model. Somewhere around 80/20 is a common compromise, but there is nothing magic about it.
❓ Questions
  • Why do we split the data into train and test data?
  • List some things that should be taken into consideration when splitting data into train and test.
  • Suppose several photos in the dataset are different leaves from the same plant. Why is it a problem if some end up in training and others in testing?
  • You report your model's accuracy to a colleague. Which of the two numbers on this page should you quote, and why does the other one not count?
✅ Answer
  • Why split. To measure generalisation. A model can score perfectly on its training images simply by memorising them, which tells you nothing. Only performance on data it never learned from estimates how it will behave on the next leaf you show it, and that is the only thing you actually care about.
  • What to consider. Keep the class distribution representative in both halves, ideally stratifying so the proportions match. Leave the test set large enough for the estimate to be stable, and the training set large enough to learn from. Make sure near-duplicates cannot straddle the split, such as the same plant, the same leaf photographed twice, or the same field session. Split along the axis you actually want to generalise over: if the model must work on a new farm, hold out whole farms rather than random images. And do not tune your model repeatedly against the test set, or it quietly stops being held out.
  • The same plant in both halves. Two photos of one plant are near-identical: same leaf shape, same lighting, same disease stage, same camera. If one is in training, the model can recognise its twin in the test set without having learned anything general, so your test score partly measures memorisation and comes out optimistically biased. This is called data leakage, and it is one of the most common reasons a model that looked excellent in development disappoints in the field.
  • Which number to quote. The test-set number, always. The training number describes how well the model reproduces answers it was explicitly fitted to, so it is not evidence about anything unseen. Quoting it is not just optimistic, it is measuring the wrong thing: a model that had simply memorised every training image would score 100% there while being useless in a greenhouse.

3 The best model ever

Before you build your own, let me offer you mine. I have developed a classifier and it reaches roughly 90% accuracy on the test set. Ninety percent, on a real biological problem, with no effort on your part. Press the button and see for yourself.

❓ Questions, before you read any further
  • Do you trust this model? Would you be willing to deploy it in a greenhouse?
  • What would you want to know before deciding? Write down what you would ask for.
✅ Answer
  • Do you trust it? You should not, and the honest answer at this point is that you do not yet have enough information to say. That is the real lesson: a single accuracy figure is not evidence, whatever its value.
  • What to ask for. A good list would include: how many of each class are there, and what does the trivial "always guess the most common class" baseline score? How does the model do on each class separately? What kinds of mistakes does it make, in a confusion matrix? How well does it rank cases, via AUROC? What does it actually predict on a handful of images I can look at? How was the test set constructed, and could it leak? If you asked for most of these, you were already thinking like a sceptic. The rest of this step works through them.

Answer those before scrolling on. The rest of this step works through what you should have asked for.

First question: how many of each class are there?

Accuracy is just the fraction of images the model gets right. That single number hides something important, and the something is the class distribution: how many of each kind of leaf there are in the first place. Drag the slider to change how many healthy leaves are in the dataset, and watch what happens to my model's accuracy.

In the full PlantVillage tomato set only about 9% of the leaves are healthy, because the dataset was built to study diseases. Real field data is often skewed the same way, and sometimes skewed the other way if most of your crop is fine. Either way, the number to beat is not 50%. It is whatever you get by always guessing the most common class.

Second question: which leaves does it get right?

Overall accuracy averages over both classes, so a model can be excellent on one and hopeless on the other without the single number ever showing it. Split the score by class and look again.

Third question: what kind of mistakes does it make?

The confusion matrix lays out all four possible outcomes instead of collapsing them into one number. Each leaf is either truly healthy or truly infected (the two rows), and the model either called it healthy or infected (the two columns). Every leaf lands in exactly one of the four boxes. The two boxes on the diagonal are the correct answers, and the two off it are the two different ways of being wrong.

Confusion matrix on the test set

Fourth question: does it rank the leaves sensibly?

There is one more angle, and it takes a little more explaining, so let's build it up slowly.

A classifier does not really answer "healthy" or "infected". It produces a score, and we compare that score against a cut-off to get an answer. Change the cut-off and you get a different set of answers from exactly the same model. So judging a model at one cut-off only tells you about that one choice.

The ROC curve gets around this by trying every possible cut-off and plotting two things at each one:

Both are things you want to trade off against each other. Catching more infections always means raising more false alarms, and the curve shows you the exchange rate. A model that is good at telling the classes apart can catch a lot of infections while raising few false alarms, so its curve bulges towards the top left. A model with no ability to discriminate can only buy catches by accepting an equal share of false alarms, so its curve runs along the diagonal. That diagonal is drawn dashed on the plot below as a reference for "no better than guessing".

The area under the curve, the AUROC, compresses that into one number: 1.0 is a perfect ranker, 0.5 is a coin flip.

ROC curve on the test set

More background on these two: thresholding and the confusion matrix and ROC and AUC.

❓ Questions
  • Does the class distribution change your view on the model's accuracy score?
  • Explain what both visualisations show exactly.
  • Based on these evaluations, does the model provide useful predictions?
  • Can you say, in one sentence, what rule this model is using to make its predictions?
  • Look back at what you wrote down earlier. Did you ask for the right things, and would you still deploy it?
✅ Answer
  • Does the distribution change your view? Completely. About 90% of these leaves are infected, so the rule "always say infected" scores about 90% by construction. The meaningful comparison for any model is against that majority-class baseline, not against 50%. Move the slider to 50% healthy and the same model drops to about 0.50, which shows the score was a property of the dataset rather than of the model.
  • What the two plots show. The confusion matrix is a table of true label against predicted label at one chosen threshold, splitting outcomes into true negatives, false positives, false negatives and true positives. It shows which mistakes are made, not just how many. Here the entire "predicted healthy" column is empty, because the model never predicts healthy. The ROC curve plots the true positive rate against the false positive rate across every possible threshold, so it describes the quality of the model's ranking independently of where you cut. Its area, the AUROC, is 1.0 for a perfect ranker and 0.5 for one carrying no information. Here the curve lies on the diagonal.
  • Useful predictions? None whatsoever. It never identifies a single healthy leaf, its accuracy on the healthy class is 0.00, and its AUROC of 0.50 says it cannot separate the classes at all. It contains no information about its input: you would get identical output with the lens cap on.
  • The rule in one sentence: "always answer infected", regardless of the image. (In the notebook this is MagicModel, whose predict literally returns an array of ones.)
  • Looking back at your list. The thing most people miss first time is the class distribution, because accuracy feels like it should already account for it. Everything else here follows from that one question. If you would still deploy this model, ask yourself what it would do in a greenhouse where most plants are healthy: it would flag every single one.

4 Training a real network

Now let's train an actual neural network and see whether it can beat that. What follows is not a demonstration or a replay. The network really is built and trained in your browser, on your machine, from the images above. That is also why it takes a few seconds.

You do not need to know the internals to follow what happens. Training works like this: the network starts with random settings and therefore guesses randomly. We show it a training image, it produces a number between 0 and 1, and we compare that with the true label. If it was wrong, every internal setting is nudged a little in the direction that would have made the answer better. Then the next image. One full pass through all the training images is called an epoch.

The model we use is a small convolutional network, the variety designed for images, which looks for local patterns like edges, spots and patches of colour rather than treating each of the 12,288 numbers as unrelated.

One thing to fix before you start

Your dataset is currently about 10% healthy, because that is what step 3 needed in order to make its point. That is a bad setting to train on. If nine out of ten training images are infected, the laziest thing the network can do is answer "infected" almost every time, and that already scores well. You will have built your own version of the model you just rejected.

So before training, raise the healthy fraction. This is the same slider as in step 3, repeated here for convenience.

Currently at 10% healthy. Training here will probably collapse into predicting "infected" for nearly everything. Raise the slider and watch the difference, or train it at 10% first to see the collapse for yourself.

Now train it

More epochs means more passes over the data and a better-fitted model, up to the point where it starts memorising. Watch the curves rather than trusting a fixed number: you want to train until the test curve stops improving.

Not trained yet.

Loss, how wrong the model is. Lower is better.

Accuracy over the same run. Higher is better.

Why two lines on each chart? The solid line is measured on the training images, the dashed line on the test images the model never learns from. When the training line keeps improving while the test line stalls or gets worse, the model has started memorising its training set rather than learning something general. That is overfitting, and the test line is the only place you can see it.

What does the network actually output?

The network does not answer "healthy" or "infected". Its final output is a single number between 0 and 1 for each image. Here are its raw outputs for ten test images:

The number under each leaf is the network's raw output; the line below it is the true label.

❓ Questions
  • What do these predicted numbers represent?
  • Look at an image where the number is close to 0.5. What does that tell you, and what would you want to happen to such a case in practice?
  • Run the training again with more epochs. What happens to the two lines on each chart, and what does the gap between them mean?
✅ Answer
  • What the outputs are. A single number between 0 and 1 per image, produced by the final sigmoid. It expresses how strongly the network leans towards class 1 (infected): near 1 means confident infected, near 0 confident healthy. It is often loosely called a probability, but it only deserves that name if you have checked that it is calibrated, that among all images scored 0.7, roughly 70% really are infected.
  • A score near 0.5. The model is undecided: whatever it extracted from the image does not clearly favour either class. In practice you would not want an automatic decision here at all. A sensible deployed system routes low-confidence cases to a human rather than forcing a call, which is often more valuable than squeezing out another percent of accuracy.
  • More epochs. The training loss keeps falling and training accuracy keeps climbing, while the test curves flatten off and eventually turn the wrong way. The gap between the solid and dashed lines is overfitting made visible: it measures how much of the model's apparent skill is memorisation of these particular images rather than something that transfers. A widening gap is the signal to stop training, get more data, or regularise.

5 Turning outputs into decisions

To get from a number between 0 and 1 to an actual decision, we need a threshold: above it we call the leaf infected, below it we call it healthy. Nothing forces that threshold to be 0.5. Choosing it is a decision about which mistake you would rather make, and it is yours to make, not the model's.

Note what the threshold does and does not change. Sliding it moves cases between the boxes of the confusion matrix, so accuracy, precision and recall all move with it. The ROC curve does not move at all: it already summarises every threshold at once. That is exactly why AUROC is a useful way to compare two models before you have decided how you want to use them.
❓ Questions
  • Which confusion matrix is more useful? The one on the train dataset or the test dataset?
  • What effect does changing the threshold have on the confusion matrix?
  • Would you prefer this deep learning model over the model you tested earlier? Why?
  • Imagine this model screens incoming plant material at a quarantine station, where letting a diseased plant through is far worse than a false alarm. Which way would you move the threshold, and what does it cost you?
✅ Answer
  • Which matrix is more useful? The test one. The training matrix shows how well the model reproduces answers it was explicitly fitted to, which is almost always flattering. Only the test matrix estimates behaviour on new leaves. That said, the training matrix is still worth a look, because comparing the two is how you spot overfitting.
  • What the threshold does. It moves cases between the columns. Raising it makes the model more reluctant to say "infected": true positives fall, false negatives rise, false positives fall, true negatives rise. Lowering it does the reverse. The row totals never change, because those are the true labels. So recall and precision move in opposite directions and accuracy has an optimum somewhere in between.
  • Prefer the neural network? Yes, but not because its accuracy number is bigger. The reason is that it actually discriminates: an AUROC well above 0.5 means it genuinely ranks infected leaves above healthy ones, so it carries information about the image. It also identifies healthy leaves, which the previous model never did, and it gives you a threshold worth tuning, a meaningless notion for a model whose output is constant.
  • The quarantine station. There, a missed infection is the expensive error, so you lower the threshold and call things infected on weaker evidence. That raises recall. What it costs is precision: more false alarms, more healthy consignments delayed, inspected or destroyed. Note that this is a policy decision about which error you can better afford, not a modelling decision, the model is the same either way.

6 Looking at the mistakes

Numbers tell you how often the model is wrong. Looking at the images tells you why. This is one of the most useful habits you can pick up: whenever a model disappoints you, go and look at the cases it got wrong. Each group below corresponds to one box of the confusion matrix, and the groups re-sort themselves as you move the threshold.

❓ Questions
  • Look at the false negatives, the infected leaves the model called healthy. Can you see, by eye, why these were hard?
  • Move the threshold up and down. Which group grows, which shrinks, and can you get both error groups to be empty at once?
  • If you had budget to photograph 200 more leaves, which kind would you go and collect, based on what you see here?
✅ Answer
  • The false negatives. They tend to be leaves where the symptoms are small, sparse or early-stage, or diseases that simply look close to healthy at 64 × 64, faint viral mottling, or a handful of tiny spots. Some are just blurry or awkwardly lit. Grouping them by disease is informative: if one category dominates, that is a concrete instruction about which data to collect next.
  • Moving the threshold. Raise it and false negatives grow while false positives shrink; lower it and the reverse. You cannot empty both at once unless the score distributions of the two classes do not overlap at all, that is, unless the model is perfect. That overlap is the model's real limitation; the threshold only lets you choose where within it you want to stand.
  • The next 200 leaves. Collect more of what it gets wrong, not more of what it already handles. Concretely: more healthy leaves, since they are the minority class and carry most of the relative error, and more of whichever disease dominates the false negatives, specifically mild and early-stage cases rather than more textbook-obvious ones. Adding easy examples of a class the model already nails buys you almost nothing.

7 When the data lies to you

Here is a story that happens more often than anyone would like. A grower photographs the healthy part of the field in the morning and walks over to the infected part later in the day, when the light has changed. Nobody notices; the photos all look fine. But every healthy photo is now slightly darker than every infected one.

Let's simulate exactly that. In the training set we darken every healthy leaf a little. And because the model will be used by other growers whose habits differ, in the test set we darken the infected ones instead. Nothing about the leaves themselves has changed. Only the lighting has.

Training set, healthy leaves darkened

Test set, infected leaves darkened

❓ Question, commit to an answer before you press the button
  • How do you think this will affect the model's performance on the training set, and on the test set?
✅ Answer

The prediction to make: training performance will look excellent, quite possibly better than before, because brightness has become a perfectly reliable clue within the training set. Test performance will be dreadful, most likely worse than guessing, because in the test set that same clue points the wrong way.

If your instinct was "it should be fine, the leaves themselves have not changed", that is exactly the intuition this step is designed to break. The model does not see leaves. It sees numbers, and we changed the numbers.

Not trained yet.

Loss. Watch the two lines pull apart.

Accuracy on the training set against the test set.

Confusion matrix on the test set (threshold 0.5)

❓ Questions
  • What do you think of the model performance?
  • How would you explain these results?
  • An AUROC below 0.5 is a strange thing to see. What does it mean about the model's ranking, and how could that come about here?
  • Nothing in the training run itself looked wrong. What would have had to happen for someone to catch this before deployment?
  • Could you think of one or more method(s) to mitigate this?
✅ Answer
  • The performance. Training accuracy is high, test accuracy is poor, and the test AUROC lands around or below 0.5. Note carefully that the model has not failed to learn. It has learned extremely well, it has just learned the wrong thing.
  • The explanation. In the training data every healthy leaf was darker. Brightness is a far simpler and more reliable pattern than lesion shape or texture, so gradient descent found it first and leaned on it: "dark means healthy". There was never any pressure to look at the disease, because the shortcut already gave a perfect answer. In the test set the darkening was applied to the infected leaves instead, so that learned rule now points precisely the wrong way.
  • AUROC below 0.5. AUROC is the probability that the model scores a randomly chosen infected leaf above a randomly chosen healthy one. 0.5 is a coin flip. Below 0.5 means it reliably ranks them the wrong way round, which is not an absence of information, it is real information being applied backwards. (Inverting every prediction would score above 0.5.) It arises exactly when a cue the model learned is anti-correlated with the label in the new data, which is what we engineered here.
  • Catching it beforehand. Nothing in the loss curves could have revealed it, and that is the uncomfortable part. In a normal project the training and test sets come from the same batch of photos, so they share the same bias and both look fine. The failure only surfaced because our test set came from a different regime. The general defences: build validation sets that genuinely differ in conditions (other farms, other days, other cameras) instead of randomly splitting one batch; record metadata such as time of day, device and operator, and check whether it predicts the label; probe what the model responds to, for instance by occluding parts of the image or testing on deliberately manipulated versions; and look at the images and how they were acquired, not only at the metrics.
  • Mitigations. Image augmentation (step 8). Standardising the acquisition protocol so lighting cannot vary with class. Per-image normalisation, so absolute brightness carries no information at all. Deliberately balancing the confounder across classes at collection time. Holding out a validation set from a different session. Best of all, fixing the data collection rather than patching it afterwards.

8 Fixing it with image augmentation

The model latched onto brightness because, in its training set, brightness was a perfectly reliable clue. One way to take that clue away is image augmentation. Before each pass we randomly mess with the training images: mirror them, brighten or darken them, nudge their contrast. The labels stay the same.

Crucially, this is re-rolled every epoch, so the model never sees the same version of an image twice. Press the button below a few times to see different random versions of the same training leaves.

The same confounded training leaves as in step 7, randomly flipped, brightened/darkened and contrast-adjusted.

Augmented images are harder to learn from, so this model usually needs more epochs than the others before it catches up. If the improvement looks disappointing, train it for longer before concluding that augmentation did not work.

Not trained yet.

Loss. Compare the gap with the one in step 7.

Accuracy on the training set against the test set.

Where are its mistakes now?

The same confusion matrix and threshold slider as in step 5, this time on the augmented model. Compare the shape of the errors against step 7. A model that has stopped leaning on brightness should spread its mistakes around rather than piling them all into one box.

Train the model above to see its confusion matrix.

Test-set ROC curves compared. Train the step 7 model first so there is something to compare against.

❓ Questions
  • Explain how image augmentation aids generalisability.
  • Augmentation did not add a single new photograph. Where, then, did the improvement come from?
  • Is augmentation a complete fix here? Compare this model against the one you trained in step 4 on clean data, and explain the difference that remains.
  • We randomly changed brightness, contrast and left–right mirroring. Why would randomly rotating leaves by 180° be fine here, but randomly changing the colour from green to brown be a terrible idea?
  • If you have extra time, pick one or more of these to investigate:
    • How is model performance changed if you shrink the dataset or change the class distribution (the slider in step 3)?
    • Could this classifier be applied to a species other than tomato? What would you need to check first?
    • Can you think of, or find, other evaluation metrics that would be useful here?
✅ Answer
  • How augmentation helps. By randomly re-rolling brightness, contrast and mirroring on every pass, those properties stop predicting the label: the same healthy leaf is sometimes dark and sometimes bright. The shortcut becomes useless, so the only way left to reduce the loss is to rely on cues that survive the randomisation, the lesions and colour patterns of the leaf itself. As a bonus it enlarges the effective variety of the training set, which reduces plain memorisation too.
  • Where the improvement came from. Not from new information, from destroying misleading information. We injected our own knowledge, namely "brightness and mirroring must not matter for this task", as a constraint on what the model is permitted to rely on. That is prior biological knowledge supplied through the data rather than through equations, which is a nice echo of the mechanistic-versus-data-driven contrast from step 0.
  • Is it a complete fix? No. Compare it against the step 4 model: augmentation recovers a great deal, but it usually still falls short of the model trained on clean data. Augmentation makes brightness harder to exploit, but the training set is still biased, the model has less clean signal to work with, and the random perturbations add noise to every image. Repairing the data collection would always have been better than patching around it afterwards.
  • Rotation versus recolouring. Rotating a leaf by 180° is safe because an upside-down leaf is still the same leaf with the same disease: the label is unchanged, so you are teaching the model a true fact, that orientation is irrelevant. Recolouring green to brown is a disaster because colour is the symptom, browning, yellowing and mottling are how several of these diseases present. You would be manufacturing images whose label no longer matches their content, teaching the model that a brown leaf can be healthy. The rule of thumb: only augment with transformations that genuinely leave the label untouched.
  • The optional investigations.
    • Smaller dataset or different class balance: shrinking the data lowers test performance and widens the train/test gap, because small datasets are memorised faster. Pushing the balance towards extreme imbalance makes accuracy look better while AUROC and minority-class recall get worse, the step 3 lesson all over again.
    • Another species: almost certainly poor without retraining. The model has only ever seen tomato leaf shapes and tomato symptoms, and other species differ in both morphology and disease repertoire. You would measure performance on a labelled sample of the new species first, and most likely fine-tune on it rather than assume transfer.
    • Other metrics: precision, recall and F1; balanced accuracy; Cohen's kappa; Matthews correlation coefficient; the area under the precision-recall curve, which is more informative than ROC AUC under strong class imbalance; recall broken down per disease; and calibration measures if you intend to treat the scores as probabilities.

✓ Check your understanding