Skip to content

nestaweb/42_leaffliction

 
 

Repository files navigation

Leaffliction

Subject requirements:

  • The functions should not quit unexpectedly
  • We are free to use any language of our choice
  • We should write 5 programs:
    • Distribution which analyzes the distribution of the dataset
    • Augmentation which augments an image 6 times using different techniques
    • Transformation which transforms an image 6 times in order to extract features
    • Train/Predict which automate the pipeline and allow to classify leafs using a neural network

Technical stack:

Usage:

git clone https://github.com/Gabriel-Angouillant/42_leaffliction
cd 42_leaffliction
unzip leaves.zip

python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

python3 train.py leaves/
python3 predict.py all

Project overview:

This project aims to create a computer vision pipeline able to recognize different leaf diseases.
Our job as a team was to process a leaf dataset, balance it using image augmentation, extract characteristics from the images, then train a neural network on the features.

An emphasis was set on obtaining a maximal accuracy on our validation dataset.

Distribution

Distribution.py allows us to easily visualize our dataset.

It takes a directory as argument, fetches images in its subdirectories then renders a pie and bar chart on the distribution of each class.

python3 Distribution.py leaves/

image

Augmentation

Augmentation.py helps in the balancing of our dataset. Every picture from the original dataset was taken in a controlled environment, making our recognition skills only efficient in this particular setup.
To fix this problem, we perform a series of augmentations (rotation, blur, contrast, scaling, illumination, projection) on all images.

The program takes a single image as argument, augments it, then renders and saves the result.

python3 Augmentation.py leaves/Apple_healthy/image\ \(1\).JPG

image

Transformation

Transformation.py is one of the most important part of this project. It is responsible for transforming images in 6 different ways (gaussian blur, mask, ROI, shape analysis, pseudolandmarks, color histogram). This workflow is implemented using PlantCV, which facilitates image processing.

From these transformations we extract features such as:

  • skew/quartiles/std for each color channel in RGB/HSV/LA
  • ellipse eccentricity
  • convex hull area
  • perimeter
  • solidity

As this program is the main indicator in how well our model will perform, we had to think of an extensive solution to allow for faster iterations through our trial and error process. Thus, we wrote the program in a way it is possible to select or randomly choose images and folders, displaying set methods and saving the transformations to a destination.

usage: Transformation.py select/random [-h]
                                [-m [{base,mask,roi,analyze,blur,histogram,psm} ...]]
                                (-d DESTINATION | -p) [-s SEED]
                                directory


python3 Transformation.py random leaves/ -p
image

Training/Prediction

train.py and predict.py respectively implement the training of the neural network model and the prediction on a given image or dataset. The training part runs the whole augmentation and transformation pipeline, normalizes the extracted features then saves the ideal weights in a model file. It separates the original dataset in two parts (train.csv/validation.csv) in order to prevent overfitting, makes use of batch normalization to prevent internal covariate shift, and drops random neurons to improve generalization.

Both programs are complementary:

python3 train.py leaves/
python3 predict.py all
python3 predict.py leaves/Apple_Black_rot/image\ \(10\).JPG
Screenshot from 2026-03-18 20-11-30 Screenshot from 2026-03-18 21-27-22 Screenshot from 2026-03-18 21-29-24

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Python 100.0%