An open API service indexing awesome lists of open source software.

https://github.com/jmcheon/leaffliction

An innovative computer vision project utilizing leaf image analysis for disease recognition.
https://github.com/jmcheon/leaffliction

image-analysis image-classification opencv-python plantcv python3 pytorch

Last synced: about 2 months ago
JSON representation

An innovative computer vision project utilizing leaf image analysis for disease recognition.

Awesome Lists containing this project

README

          

# Leaffliction - Computer vision
>*_Summary: Image classification by disease recognition on leaves._*

| Requirements | Skills |
|--------------|--------|
| - `python3.10`
- `torch`
- `torchvision`
- `opencv`
- `plantcv`
- `numpy`
- `matplotlib`
| - `Rigor`
- `Group & interpersonal`
- `Algorithms & AI` |

## Usage
There are 4 distinct parts in this project, `01. Distribution`, `02. Augmentation`, `03. Transformation`, and `04. Classification`.

### 01. Distribution
Download image dataset and generate distribution chart image
```bash
usage: 01.Distribution.py [-h] directories [directories ...]

A program to analyze plant images and generate charts.

positional arguments:
directories The directories to store extracted images and save the charts (ex: 01.Distribution apple)

options:
-h, --help show this help message and exit
```

#### Example
```bash
python3 01.Distribution.py apple grape
```


### 02. Augmentation
Augment unbalanced image dataset
```bash
usage: 02.Augmentation.py [-h] [file_path]

A program to augment images samples by applying 6 types of transformation.

positional arguments:
file_path Image file path to transform to 6 different types.

options:
-h, --help show this help message and exit
```

#### Example
```bash
python3 02.Augmentation.py
```


### 03. Transformation
Save transformed image plots

```bash
usage: 03.Transformation.py [-h] -src [SRC_PATH] [-dst [DST_PATH]] [-gaussian] [-mask] [-roi] [-analyze] [-pseudo] [-hist]

A program to display image transformation.

options:
-h, --help show this help message and exit
-src [SRC_PATH], --src_path [SRC_PATH]
Image file path.
-dst [DST_PATH], --dst_path [DST_PATH]
Destination directory path.
-gaussian, --gaussian_blur
Gaussian Transform
-mask Mask Transform
-roi, --roi_objects Roi Transform
-analyze, --analyze_object
Analyze Transform
-pseudo, --pseudolandmarks
Psudolandmark Transform
-hist, --color_histogram
Color histogram Transform
```

#### Example
```bash
python3 03.Transformation.py -src [SRC_PATH] -dst [DST_PATH]
```


### 04. Classification
Print the accuracy on validation dataset

```bash
usage: 04.Classification.py [-h] [folder_path]

A program to classify a type of leaf from validation set.

positional arguments:
folder_path Image folder path.

options:
-h, --help show this help message and exit
```

#### Example
```bash
python3 04.Classification
```




## Implementation

### Leaf Classifier CNN Model
The model is designed to classify leaf diseases based on images of leaves. The model is implemented using Pytorch and consists of 4 convolutional layers followed by max pooling, along with 2 fully connected layers. The final output is produced using a softmax function for multi-class classification.

#### Model Architecture
1. Input layer
- Input: Leaf images with a shape of (256, 256, 3) corresponding to 256 x 256 RGB images.

2. Convolutional layers
- Conv Layer 1
- Input channels: 3 (RGB)
- Output channels: 32
- Kernel size: 3 x 3
- Activation function: ReLU
- Max Pooling: 2 x 2
- Conv Layer 2
- Input channels: 32
- Output channels: 64
- Kernel size: 3 x 3
- Activation function: ReLU
- Max Pooling: 2 x 2
- Conv Layer 3
- Input channels: 64
- Output channels: 128
- Kernel size: 3 x 3
- Activation function: ReLU
- Max Pooling: 2 x 2
- Conv Layer 4
- Input channels: 128
- Output channels: 256
- Kernel size: 3 x 3
- Activation function: ReLU
- Max Pooling: 2 x 2

3. Fully connected layers
- FC Layer 1
- Input: Flattened tensor from the previous convolutional layers (256 * 14 * 14 = 50176 units)
- Output: 512 units
- Activation function: ReLU
- Dropout: 0.5
- FC Layer 2
- Input: 512 units
- Output: `NUM_CLASSES` units (representing the number of disease classes)
- Activation function: Softmax

## Visualization

### 01. Distribution
There are 2 distinct leaf types; `apple` and `grape`, each of which consists of 4 labels.



Apple Image Distribution


Grape Image Distribution




apple image distribution


grape image distribution

### 02. Augmentation
The following 6 image augmentation techniques are applied to one single-leaf image labeled `apple black rot`.



Brightness


Contrast


Flip


Perspective


Rotate


Saturation




augmentation brightness image


augmentation contrast image


augmentation flip image


augmentation perspective image


augmentation rotate image


augmentation saturation image

### 03. Transformation
The following 6 image transformation techniques are applied to one single-leaf image labeled `apple black rot`.



Mask


Gaussian Blur


Roi objects


Analyze object


Pseudolandmarks




transformation mask image


transformation gaussian blur image


transformation roi objects image


transformation analyze object image


transformation pseudolandmarks image






Color Histogram




color histogram image

### 04. Classification

#### Tensorboard
To visualize the learning curves using tensorboard, execute the following command.
```
tensorboard --logdir runs
```

#### Validation Accuracy
validation accuracy

#### Test Accuracy
We have 10 test images and the model has 100% accuracy


predicted example1

## Resources
- [Youtube Coursera CNN](https://www.youtube.com/playlist?list=PLkDaE6sCZn6Gl29AoE31iwdVwSG-KnDzF)