Skip to content

Latest commit

 

History

17 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FastAI Segmentation for Oat Leaves

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

Table of Contents

Introduction

This project aims to segment oat leaves from images using a deep learning model built with FastAI and PyTorch.

Installation

To install use Miniconda to install the required dependencies, run:

conda env create -f environment.yml

Activate Environment

To enter the newly created environment, run:

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. Ensure the dataset is organized in the following structure:

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

Remove Backgrounds

If the images in the dataset still have backgrounds, this project contains a package to remove them. It uses Meta's SAM 2 model to get the foreground oat leaf image. It works best when the oat leaf is the primary element in the image.

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

Arguments

  • -d (--dataset-path): Path to the dataset directory (required).
  • -o (--output-path): Path to save the prepared dataset (required).

Output

The output dataset will be organized in the following structure:

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

Comparison Output

If mask comparison (-c | --comparison) is on, the output dataset will be organized in the following structure:

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

Models

Pretrained models are available to be used when running these models for inferencing.

Evaluation

To evaluate the model, first install and activate the conda environment. Then run:

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

Arguments

  • -m (--model-path): Path to the model pkl file (required).
  • -d (--dataset-path): Path to the dataset directory (required).
  • -c (--compare): Toggle to save comparison mask images (optional).
  • --cuda: Specify the CUDA device to use for model inference (optional, default is 0). If there is no CUDA device on the system, CPU will be used.
  • --bootstrap-samples: Number of bootstrap samples to generate (optional, default is 1,000).
  • --bootstrap-confidence: Confidence level for bootstrap samples (optional, default is 0.95).
  • --save-pustule-edge: Toggle to save images with pustule edges outlined (optional).
  • --image-split: Split the dataset into smaller parts for processing (optional, default is 0 for no splitting). Increasing this value can help reduce RAM and GPU memory usage by processing fewer images at a time.
  • --cpu-count: Number of CPU cores to use for multiprocessing (optional, default is 0 for all available cores). Reducing this value can help lower RAM memory usage by limiting number of images being processed at a time.

Contributing

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

About

Tool for running FastAI trained models for Oat Plant Segmentation

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages