Skip to article

Semi-supervised plant disease detection in Rust

Jan 24, 2026Rust, Burn, semi-supervised learning, edge AI

~460KParameters
38Disease classes
20%Labeled data
0.42msMean inference

In my fifth semester at Howest I did a research project with three goals. I wanted to build a complete machine learning pipeline in Rust with the Burn framework, train a plant disease classifier on very little labeled data using semi-supervised learning, and get it running offline on desktop, in the browser, and on mobile.

The code, experiment outputs, and thesis documents are in the public repository.

The problem

The users are farmers who need to recognize plant diseases in places with poor or no internet. Getting an expert or a lab to identify a disease can be slow and expensive, and running the model in the cloud needs a stable connection. In a lot of fields you can't count on either.

So the app had to:

  • work 100% offline
  • run on devices farmers already own (phones, laptops)
  • install without any hassle (farmers are not sysadmins)
  • return a result in under a second, so the feedback feels immediate

Labeled agricultural data is also expensive. Expert annotation costs about €2 per image, so 50,000 images would cost €100K, which we don't have. The pipeline has to learn well from a small labeled subset.

Why Rust and Burn

I chose Rust and Burn (v0.21.0) because what this project needed lines up well with what Rust is good at.

One binary to ship

Burn compiles to a single binary with no external runtime dependencies. With LTO and codegen-units = 1 in the release profile, the model and the inference runtime ship as one file. There's no virtual environment, package manager, or install step, which matters when your users are farmers who are never going to run pip install, this matters.

Several backends, one codebase

Burn supports multiple compute backends through Rust's trait system:

  • burn-cuda for native CUDA (desktop GPU training and inference)
  • burn-wgpu for cross-platform GPU via Vulkan, Metal, and DX12
  • burn-ndarray as a CPU-only fallback with no dependencies

The same model definition compiles for all of them and uses the same weights, and everything from training to production is written in one language.

Fast startup

Burn loads in under 100ms. People expect a phone app to respond right away, so startup time matters as much as inference time.

Model architecture

The classifier is a small CNN with four convolutional blocks and about 460,000 parameters:

Input: [B, 3, 128, 128]

Conv2d(3, 32, 3x3, pad=same)   -> BatchNorm -> ReLU -> MaxPool(2x2)
Conv2d(32, 64, 3x3, pad=same)  -> BatchNorm -> ReLU -> MaxPool(2x2)
Conv2d(64, 128, 3x3, pad=same) -> BatchNorm -> ReLU -> MaxPool(2x2)
Conv2d(128, 256, 3x3, pad=same)-> BatchNorm -> ReLU -> MaxPool(2x2)

AdaptiveAvgPool2d(1x1) -> Flatten
Linear(256, 256) -> ReLU -> Dropout(0.3)
Linear(256, 38)

Output: [B, 38] logits

Inputs are 128x128 RGB images, normalized with the ImageNet statistics (mean = [0.485, 0.456, 0.406], std = [0.229, 0.224, 0.225]). The 38 outputs are the plant disease classes from the PlantVillage dataset.

The B: Backend trait bound makes the model generic over the backend, so this one struct compiles to CUDA, CPU, or wgpu without any duplicated code:

#[derive(Module, Debug)]
pub struct PlantClassifier<B: Backend> {
    conv1: Conv2d<B>,
    bn1: BatchNorm<B, 2>,
    conv2: Conv2d<B>,
    bn2: BatchNorm<B, 2>,
    conv3: Conv2d<B>,
    bn3: BatchNorm<B, 2>,
    conv4: Conv2d<B>,
    bn4: BatchNorm<B, 2>,
    fc1: Linear<B>,
    fc2: Linear<B>,
}

The semi-supervised pipeline

This is the main part of the project. Only 20% of the data had labels, so I needed a way to use the other 80%. I went with iterative pseudo-labeling, also called self-training.

Splitting the data

The ~87,000 PlantVillage images are split with stratification:

Total dataset (~87K images)
  |-- Test set:       10% (~8.7K)   -- never seen during training
  |-- Validation set: 10% (~8.7K)   -- for monitoring and early stopping
  |-- Labeled pool:   20% (~17.4K)  -- used for supervised training
  |-- Stream pool:    60% (~52.2K)  -- unlabeled, used for SSL

Pseudo-labeling

You train a model on the labeled data, use it to label the rest, and retrain on the bigger set. Whether that works or slowly fills the training set with noise depends on the details.

For each unlabeled sample xux_u, the model produces:

p=softmax(f(xu))p = \text{softmax}(f(x_u))

The predicted class and its confidence are:

y^=arg⁡max⁡(p),c=max⁡(p)\hat{y} = \arg\max(p), \quad c = \max(p)

A pseudo-label is only accepted when the confidence reaches a threshold τ\tau:

c≥τ(τ=0.9)c \geq \tau \quad (\tau = 0.9)

A 90% threshold is strict on purpose, because low-confidence predictions poison the training set. The final evaluation didn't separately measure how many pseudo-labels were correct, so read the threshold as a setting in the pipeline, not as a result.

Loss function

For labeled data, the loss is standard cross-entropy:

Llabeled=−1N∑i=1Nlog⁡(softmax(f(xi))yi)\mathcal{L}_{\text{labeled}} = -\frac{1}{N}\sum_{i=1}^{N} \log\left(\text{softmax}(f(x_i))_{y_i}\right)

Pseudo-labeled data uses a negative log-likelihood weighted by confidence. Each sample counts in proportion to how confident the model was when it made that pseudo-label:

Lpseudo=∑i=1Mwi⋅(−log⁡(softmax(f(xi))y^i))∑i=1Mwi+ϵ\mathcal{L}_{\text{pseudo}} = \frac{\sum_{i=1}^{M} w_i \cdot \left(-\log\left(\text{softmax}(f(x_i))_{\hat{y}_i}\right)\right)}{\sum_{i=1}^{M} w_i + \epsilon}

where wiw_i is the confidence score of pseudo-label ii and ϵ=10−8\epsilon = 10^{-8} prevents division by zero.

The total loss adds the two, with a ramp-up on the pseudo-label term:

Ltotal=Llabeled+λ⋅ramp(t)⋅Lpseudo\mathcal{L}_{\text{total}} = \mathcal{L}_{\text{labeled}} + \lambda \cdot \text{ramp}(t) \cdot \mathcal{L}_{\text{pseudo}}

The ramp-up raises the pseudo-label weight linearly over the first TrampT_{\text{ramp}} epochs:

ramp(t)=min⁡(tTramp,1),Tramp=10\text{ramp}(t) = \min\left(\frac{t}{T_{\text{ramp}}}, 1\right), \quad T_{\text{ramp}} = 10

Early in training the predictions are still unreliable, and this keeps the pseudo-labels from taking over before the model is ready.

Simulating deployment

The SSL pipeline simulates new images arriving every day, the way they would if a farmer kept photographing their crops:

  1. Train on the 20% labeled pool first, with cross-entropy and Adam (lr = 0.0001, weight decay = 1e-4).
  2. Each simulated day, run inference on a batch of 100 images from the stream pool.
  3. Keep predictions with a confidence of at least τ=0.9\tau = 0.9, capped at 500 pseudo-labels per class so the classes stay balanced.
  4. Collect them in a buffer until it reaches the retraining threshold of 200 samples.
  5. Retrain on the labeled data plus the collected pseudo-labels, with augmentation applied on the fly.
  6. Repeat until the stream pool is empty.

Inference runs on clean, unaugmented images, so the pseudo-labels come from clean predictions. Retraining does use augmentation, to prevent overfitting: horizontal flips (p=0.5), rotation up to 20 degrees (p=0.5), brightness and contrast jitter (p=0.5), and light Gaussian noise (p=0.1). I wrote all of it from scratch in Rust, without an image augmentation library.

Results

Both models started from the same 20% of labeled data and were tested on the same held-out split of 8,786 images. The saved SSL checkpoint did a lot better than the saved supervised baseline:

MetricSupervised onlyAfter SSL
Held-out top-1 accuracy86.06%94.90%
Held-out macro F186.08%94.74%
Held-out test images8,7868,786

That's 8.84 percentage points more accuracy and 8.66 points more macro F1. The numbers come from one saved split and one random seed. PlantVillage images are fairly uniform and look like they were taken in a lab, so don't expect the same performance out in a real field.

Deployment

There are three deployment targets, and they don't all work the same way.

Desktop: Tauri v2 + SvelteKit

The desktop application uses Tauri v2 with a SvelteKit 5 frontend and a Rust backend. The backend exposes more than 30 Tauri commands that connect the Svelte UI straight to GPU operations, so it does a lot more than wrap a webview. Training runs inside tokio::task::spawn_blocking and sends events to the frontend as it goes, so the GUI can show training progress, confidence distributions, and benchmark results live.

Tauri desktop GUI showing model diagnostics and training progress
Figure 1: The Tauri v2 desktop app with its SvelteKit frontend, showing live training, the SSL simulation, and benchmark charts.

Browser and mobile: ONNX Runtime Web

Compiling Burn straight to WASM for the browser and mobile wasn't viable, so I built an export pipeline instead:

Burn modelRust weights
JSON exportWeight extraction
ONNX conversionvia a PyTorch bridge
ONNX Runtime WebBrowser inference

The PWA works fully offline through a service worker. The first visit caches the ~1.8MB ONNX model, and after that it works in airplane mode. I also had to write my own bilinear resize in JavaScript that matches PIL/Pillow's implementation exactly, so the browser preprocesses images the same way the training pipeline does. If the resize interpolation is off by a single pixel, accuracy collapses and nothing tells you why.

PlantVillage AI running on iPhone 12 as an offline PWA
Figure 2: The model running offline as a PWA on my iPhone 12. ONNX Runtime Web does the inference, so there is no native app to install.

Benchmarks

I ran the same benchmark on every hardware setup: 100 iterations after 10 warmup runs, batch size 1, 128x128 input.

Burn (Rust) on CUDA

Model versionMean (ms)p50 (ms)p99 (ms)Throughput
Baseline0.410.310.93~2,428 FPS
SSL0.420.251.09~2,406 FPS

Hardware comparison

DeviceLatencyThroughputCost
Laptop (RTX 3060)0.42ms~2,406 FPS€0 (BYOD)
Jetson Orin Nano~120ms~8 FPS€350
iPhone 12 (Tauri Mobile / Rust)~80ms~12 FPS€0 (BYOD)
CPU only~250ms~4 FPS€0

The Jetson surprised me. It costs €350 and took ~120ms per image, while a phone the farmer already owns took ~80ms. After that I switched completely to a BYOD (bring your own device) approach. Every device stays under the 200ms real-time target except plain CPU, which comes in at 250ms.

Incremental learning

If the model can't learn new diseases after it's deployed, it will go out of date. So I built incremental learning with four strategies, each implementing the same generic Rust trait:

pub trait IncrementalLearner<B: Backend> {
    fn learn_incremental(
        &mut self,
        new_data: &[DataPoint],
        config: &IncrementalConfig,
    ) -> IncrementalResult;
}

Fine-tuning

Retrain on the new data. It's simple, but the model can forget classes it learned before (catastrophic forgetting).

LwF (Learning without Forgetting)

Distills knowledge from the old model, so it keeps what it learned without storing the old training data.

EWC (Elastic Weight Consolidation)

Uses the Fisher information matrix to penalize changes to important weights. It needs little memory and has a solid theoretical basis.

Rehearsal

Replays stored samples from earlier tasks, picked by herding, at random, or by distance.

With this, a farmer could photograph a new disease variant, have an expert label a small batch, and the model would update on the device itself, without going through the cloud or being redeployed.

What I learned

  • Burn is ready for production inference. The API is clean, switching backends works, and the community responds quickly. Training is still less comfortable than in the established frameworks.
  • For the browser, ONNX was the practical route. Exporting to ONNX and letting ONNX Runtime Web run the model worked, and fighting to compile Burn to WASM didn't.
  • Dedicated edge hardware is often overkill. The €350 Jetson was slower than the phone, and for a model this size, ordinary consumer devices are fast enough for most inference.
  • Preprocessing has to match exactly. A small difference in resize interpolation between training and inference wrecks accuracy without any error, so every target needs the exact same preprocessing.
  • Rust's compile times are a real cost. Expect release builds of 5+ minutes. Incremental debug builds are fast, but CI and releases are slow.
  • Tauri v2 works well for ML apps. A Rust backend with a web frontend gives you native GPU access and modern UI tools, and the command/event system connects the two cleanly.

Conclusion

The project started with the question "can we run ML on a farm?" and turned into a long look at Rust's ML ecosystem. The answer is yes, with caveats.

With only 20% of the images labeled, pseudo-labeling raised test accuracy from 86.06% for the supervised baseline to 94.90%. Burn compiled the same model for desktop GPU and CPU, and through ONNX it also runs in the browser. Tauri v2 turned all of that into a real application with a proper GUI.

Rust's ML ecosystem is younger than Python's and still has rough edges. For getting a trained model onto limited devices that have to work offline, though, it did what I needed. Data loading, augmentation, training, and inference are all in one language, and that made the project a lot simpler to work on.

A semester 5 research project at Howest MCT, built with Burn, Tauri, and ONNX Runtime.

Warre Snaet, 2026. Questions about this? Email me.