Gemma4-E2B-corps-v1 is a highly accurate, AI-driven image classification model fine-tuned for crop disease diagnosis. Built on top of the Gemma4-E2B-IT base model, it leverages a vision encoder and is optimized for inference on edge devices due to its compact size of 2 billion active parameters.
The model predicts structured JSON outputs, identifying both the crop type (out of 14 categories) and its specific health status (out of 67 possible conditions).
Problem Statement & Motivation
By 2050, the global population is projected to reach nearly 9.7 billion, requiring a massive surge in food production.
Currently, 20% to 40% of global crop yields are lost annually to plant pests and diseases, representing over $220 billion in economic damage.
Traditional disease diagnosis relies heavily on expert agricultural knowledge, which is often expensive, localized, and too slow to stop an outbreak.
This model democratizes expert-level agronomy by allowing farmers to instantly detect and diagnose crop diseases from simple images, ultimately safeguarding food security and smallholder farmer livelihoods.
Dataset
The core training data was acquired from the Plant Diseases 100K Labelled Images dataset.
Dataset Characteristics
Scale: Contains over 100,000 high-resolution images, providing a robust sample size necessary for training deep neural networks without severe overfitting.
Each category includes imagery of both healthy leaves and leaves exhibiting various pathogenic states, enabling the model to learn specific visual boundaries.
Statuses: The model categorizes 67 distinct health statuses across these crops.
Data Distribution
Distribution
Class Imbalance Handling
Because the dataset is not perfectly balanced across all 67 statuses, the training process minimizes cross-entropy loss by prioritizing larger classes in samples.
Weights are calculated for each class at the status level. During training, the average loss of response tokens per sample is calculated and multiplied by the specific status weight before being averaged for backpropagation.
Usage & Prompt Engineering
The model utilizes its Instruct (IT) capabilities to output highly structured JSON data. The generation follows an autoregressive format: predicting the crop first and then generating the specific status.
Example Prompt Payload
json
1{2"role":"user",3"content":[4{5"type":"image"6},7{8"type":"text",9"text":"Analyze the following image of a crop. Identify the type of crop and its health status. Output your findings strictly as a JSON object with 'crop' and 'status' keys."10}11]12}
bfloat16 sets the math precision to 16-bit to prevent mathematical overflows during training.
Quantization
4-bit Quantization was used to compress model weights and drastically reduce GPU VRAM usage. Specifically, NormalFloat4 (NF4) was utilized for better intelligence retention.
Weights temporarily de-quantize to BF16 during active math calculations.
Gradient Checkpointing
Enabled as a massive memory saver; it re-computes intermediate activations during the backward pass rather than storing them for the entire network.
Parameter Efficient Fine-Tuning (LoRA)
Parameter
Value
Target Modules
Default layers (attention query and value projection matrices)
Rank (r)
16
Alpha
32
Dropout
0.05
Bias
None
Hyperparameters
Parameter
Value
Optimizer
paged_adamw_8bit
Batch Size
32
Epochs
3
Learning Rate
2e-4
Scheduler
Cosine Annealing
Warmup Ratio
0.03
Gradient Clipping
0.3
Hyperparameter Notes
Optimizer: Compresses AdamW states to 8-bit and offloads data to CPU RAM to prevent Out Of Memory crashes.
Learning Rate Scheduler: Gradually decreases the learning rate following a cosine curve to help convergence.
Warmup Ratio: Starts from 0 and reaches the target learning rate during the first 3% of training.
Gradient Clipping: Prevents exploding gradients by scaling down excessively large updates.
Training Results
The model exhibited strong and continuous convergence throughout all three epochs.