This repository contains pretrained segmentation models for oat leaf segmentation using the FastAI library.
This project aims to segment oat leaves from images using a deep learning model built with FastAI and PyTorch.
To install use Miniconda to install the required dependencies, run:
conda env create -f environment.ymlTo enter the newly created environment, run:
conda activate fastai-segTo use the segmentation model, follow these steps:
- Prepare your dataset.
- Use the provided trained models to segment oat leaves in new images.
The dataset should contain images of oat leaves. Ensure the dataset is organized in the following structure:
images/
├── image1.jpg
├── image2.jpg
└── ...
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
-d(--dataset-path): Path to the dataset directory (required).-o(--output-path): Path to save the prepared dataset (required).
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
└── ...
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
└── ...
Pretrained models are available to be used when running these models for inferencing.
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-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 is0). If there is no CUDA device on the system, CPU will be used.--bootstrap-samples: Number of bootstrap samples to generate (optional, default is1,000).--bootstrap-confidence: Confidence level for bootstrap samples (optional, default is0.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 is0for 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 is0for all available cores). Reducing this value can help lower RAM memory usage by limiting number of images being processed at a time.
Contributions are welcome! Please open an issue or submit a pull request.