FastAI Segmentation for Oat Leaves

This repository contains pretrained segmentation models for oat leaf segmentation using the FastAI library.

View the source code on GitHub.

Table of Contents

Installation

To install the required dependencies, use Miniconda:

conda env create -f environment.yml

For more details on Miniconda, visit the official Miniconda documentation.

Activate the environment:

conda activate fastai-seg

Usage

To use the segmentation model, follow these steps:

  1. Prepare your dataset.
  2. Use the provided trained models to segment oat leaves in new images.

Dataset

The dataset should contain images of oat leaves organized in the following structure:

images/
├── image1.jpg
├── image2.jpg
└── ...

Remove Backgrounds

If the images still have backgrounds, use the following command to remove them by leveraging Meta's SAM (Segment Anything Model), which provides accurate and efficient background removal capabilities:

python3 -m segment.prepare -d path/to/dataset -o path/to/output

Output

The output dataset will be organized as follows:

images/
├── data_[model_name]/
│   ├── masks/
│   │   ├── image1.png
│   │   ├── image2.png
│   │   └── ...
|   ├── predictions_[model_name]_bootstrap.csv
│   └── predictions_[model_name].csv
├── image1.jpg
├── image2.jpg
└── ...

Predictions

The predictions file contains detailed information about the segmentation results for each image in the dataset. Each row corresponds to an image, and the columns provide metrics such as the proportion of each class, estimated pustules, pixel counts, and statistical measures like circularity and area. These metrics are useful for analyzing the segmentation performance and extracting insights about the dataset.

Predictions Bootstrap

The predictions bootstrap file provides confidence intervals and statistical summaries for the segmentation metrics. It is generated using bootstrap sampling with a specified number of samples (e.g., 1,000) and confidence level (e.g., 95%). This file is useful for understanding the variability and reliability of the segmentation results.

Classes

The following classes are identified in the segmentation process, based on the configuration file:

Models

Pretrained models are available for inferencing.

This script utilizes pretrained models specified by the -m tag. The -m tag allows the user to select a particular pretrained model to be loaded and used for inference or fine-tuning. The models are typically pre-trained on large datasets and can be leveraged to perform tasks such as classification, object detection, or other machine learning tasks without the need to train from scratch. Ensure that the specified model is compatible with the script's framework and dependencies.

Evaluation

To evaluate the model, run the following command:

python3 -m segment.predict -m path/to/model.pkl -d path/to/dataset -c

Arguments

Result

Below is the comparison of the input image and the resulting colorized mask produced by the inference of the model.

Contributing

Contributions are welcome! Please open an issue or submit a pull request.