Update README: remove gated access, add model details and demo links
Browse files
README.md
CHANGED
|
@@ -6,108 +6,198 @@ tags:
|
|
| 6 |
- image-segmentation
|
| 7 |
- pytorch
|
| 8 |
- unet
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
language:
|
| 10 |
- en
|
| 11 |
---
|
| 12 |
|
| 13 |
-
# Gray Leaf Spot Segmentation Model
|
| 14 |
|
| 15 |
-
PyTorch U-Net
|
| 16 |
|
|
|
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
|
| 20 |
-
- `best_area_w_0.1.pt`: area consistency U-Net (weight=0.1)
|
| 21 |
-
- `best_area_w_0.3.pt`: area consistency U-Net (weight=0.3)
|
| 22 |
-
- `best_area_w_0.5.pt`: area consistency U-Net (weight=0.5)
|
| 23 |
-
- `best_area_w_0.7.pt`: area consistency U-Net (weight=0.7)
|
| 24 |
-
- `requirements.txt`: minimal runtime dependencies
|
| 25 |
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
```python
|
| 29 |
import torch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
-
model =
|
|
|
|
| 32 |
model.eval()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
```
|
| 34 |
|
| 35 |
-
##
|
| 36 |
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
### Environment Setup (Apple Silicon recommended)
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
```
|
| 48 |
|
| 49 |
### Dataset Preparation
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
|
| 57 |
### Training
|
| 58 |
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
|
| 79 |
### Best Practices
|
| 80 |
|
| 81 |
-
-
|
| 82 |
-
- Use augmentations and area
|
| 83 |
- Inspect overlay outputs to verify mask quality.
|
| 84 |
-
-
|
| 85 |
|
|
|
|
| 86 |
|
|
|
|
| 87 |
|
|
|
|
| 88 |
|
|
|
|
| 89 |
|
| 90 |
-
|
| 91 |
|
| 92 |
-
|
| 93 |
|
| 94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
@misc{rohan_r_2026,
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
}
|
| 103 |
```
|
| 104 |
|
| 105 |
-
|
| 106 |
## License
|
| 107 |
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
## Access
|
| 111 |
-
|
| 112 |
-
This repository is gated with manual approval enabled on the Hugging Face Hub.
|
| 113 |
-
Users must request access before they can download the model.
|
|
|
|
| 6 |
- image-segmentation
|
| 7 |
- pytorch
|
| 8 |
- unet
|
| 9 |
+
- fungal-colony
|
| 10 |
+
- petri-dish
|
| 11 |
+
- morphometry
|
| 12 |
+
- magnaporthe
|
| 13 |
+
- area-consistency
|
| 14 |
language:
|
| 15 |
- en
|
| 16 |
---
|
| 17 |
|
| 18 |
+
# π¬ Gray Leaf Spot Segmentation Model
|
| 19 |
|
| 20 |
+
PyTorch U-Net models for **gray leaf spot** (*Magnaporthe* and related fungal) colony segmentation on 90 mm petri-dish images.
|
| 21 |
|
| 22 |
+
**[βΆ Try the live demo](https://huggingface.co/spaces/rotsl/grayleafspot-segmentation-demo)** β upload images, run inference, see overlays & growth charts in your browser.
|
| 23 |
|
| 24 |
+
---
|
| 25 |
+
|
| 26 |
+
## Model Weights
|
| 27 |
+
|
| 28 |
+
| File | Architecture | Params | Area-Consistency Weight | Description |
|
| 29 |
+
|---|---|---|---|---|
|
| 30 |
+
| `grayleafspot.pt` | smp.Unet (ResNet-34) | ~24.4 M | β | Main encoderβdecoder model |
|
| 31 |
+
| `best_area_w_0.1.pt` | SmallUNet | ~250 K | 0.1 | Light area regularisation |
|
| 32 |
+
| `best_area_w_0.3.pt` | SmallUNet | ~250 K | 0.3 | Moderate area regularisation |
|
| 33 |
+
| `best_area_w_0.5.pt` | SmallUNet | ~250 K | 0.5 | Balanced BCE + area |
|
| 34 |
+
| **`best_area_w_0.7.pt`** | **SmallUNet** | **~250 K** | **0.7** | **Strong area consistency (used by demo)** |
|
| 35 |
+
|
| 36 |
+
All SmallUNet variants share the same architecture:
|
| 37 |
+
|
| 38 |
+
```
|
| 39 |
+
Input (3 Γ 256 Γ 256)
|
| 40 |
+
β
|
| 41 |
+
ββ enc1: ConvBlock(3 β 16) βββ skip s1
|
| 42 |
+
ββ enc2: MaxPool2d β ConvBlock(16 β 32) βββ skip s2
|
| 43 |
+
ββ enc3: MaxPool2d β ConvBlock(32 β 64) βββ skip s3
|
| 44 |
+
ββ enc4: MaxPool2d β ConvBlock(64 β 128) βββ skip s4
|
| 45 |
+
β
|
| 46 |
+
ββ bottleneck: MaxPool2d β ConvBlock(128 β 256)
|
| 47 |
+
β
|
| 48 |
+
ββ up4: Upsample + cat(s4) β ConvBlock(384 β 128)
|
| 49 |
+
ββ up3: Upsample + cat(s3) β ConvBlock(192 β 64)
|
| 50 |
+
ββ up2: Upsample + cat(s2) β ConvBlock(96 β 32)
|
| 51 |
+
ββ up1: Upsample + cat(s1) β ConvBlock(48 β 16)
|
| 52 |
+
β
|
| 53 |
+
ββ head: Conv2d(16 β 1) β Sigmoid
|
| 54 |
+
```
|
| 55 |
|
| 56 |
+
Each `ConvBlock` = Conv3Γ3 (no bias) β ReLU β Conv3Γ3 (no bias) β ReLU.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
+
| Property | Value |
|
| 59 |
+
|---|---|
|
| 60 |
+
| **Input** | 256 Γ 256 RGB |
|
| 61 |
+
| **Output** | 1-channel sigmoid probability mask |
|
| 62 |
+
| **Training loss** | BCE + area-consistency loss |
|
| 63 |
+
| **CPU compatible** | β
Pure PyTorch β no custom CUDA kernels |
|
| 64 |
+
|
| 65 |
+
---
|
| 66 |
+
|
| 67 |
+
## Quick Start
|
| 68 |
+
|
| 69 |
+
### Download & Inference (SmallUNet)
|
| 70 |
|
| 71 |
```python
|
| 72 |
import torch
|
| 73 |
+
from huggingface_hub import hf_hub_download
|
| 74 |
+
|
| 75 |
+
# Download weights
|
| 76 |
+
path = hf_hub_download("rotsl/grayleafspot-segmentation", "best_area_w_0.7.pt")
|
| 77 |
+
|
| 78 |
+
# Load checkpoint
|
| 79 |
+
ckpt = torch.load(path, map_location="cpu", weights_only=False)
|
| 80 |
+
|
| 81 |
+
# Build model (SmallUNet architecture β see demo repo for full class definition)
|
| 82 |
+
# https://huggingface.co/rotsl/grayleafspot-segmentation-demo/blob/main/app.py
|
| 83 |
+
from model import SmallUNet # or copy the class from the demo app.py
|
| 84 |
|
| 85 |
+
model = SmallUNet(in_channels=3, out_channels=1, base_channels=16)
|
| 86 |
+
model.load_state_dict(ckpt["model_state_dict"])
|
| 87 |
model.eval()
|
| 88 |
+
|
| 89 |
+
# Run inference on a 256Γ256 RGB tensor
|
| 90 |
+
import numpy as np
|
| 91 |
+
from PIL import Image
|
| 92 |
+
|
| 93 |
+
img = Image.open("petri_dish.jpg").convert("RGB").resize((256, 256))
|
| 94 |
+
x = torch.from_numpy(np.array(img).transpose(2, 0, 1)).float() / 255.0
|
| 95 |
+
x = x.unsqueeze(0)
|
| 96 |
+
|
| 97 |
+
with torch.no_grad():
|
| 98 |
+
prob = model(x)[0, 0].numpy()
|
| 99 |
+
|
| 100 |
+
mask = (prob > 0.5).astype(np.uint8) * 255
|
| 101 |
+
Image.fromarray(mask).save("colony_mask.png")
|
| 102 |
```
|
| 103 |
|
| 104 |
+
### Download & Inference (Main U-Net)
|
| 105 |
|
| 106 |
+
```python
|
| 107 |
+
import torch
|
| 108 |
+
|
| 109 |
+
path = hf_hub_download("rotsl/grayleafspot-segmentation", "grayleafspot.pt")
|
| 110 |
+
model = torch.load(path, map_location="cpu", weights_only=False)
|
| 111 |
+
model.eval()
|
| 112 |
+
```
|
| 113 |
+
|
| 114 |
+
---
|
| 115 |
+
|
| 116 |
+
## Training & Inference Pipeline
|
| 117 |
|
| 118 |
### Environment Setup (Apple Silicon recommended)
|
| 119 |
|
| 120 |
+
```bash
|
| 121 |
+
python3.10 -m venv trainenv
|
| 122 |
+
source trainenv/bin/activate
|
| 123 |
+
pip install --upgrade pip
|
| 124 |
+
pip install -r requirements.txt
|
| 125 |
+
```
|
|
|
|
| 126 |
|
| 127 |
### Dataset Preparation
|
| 128 |
|
| 129 |
+
Place raw images in `raw/` and corresponding masks in `masks/` (matching filenames). Expand the dataset with augmentations:
|
| 130 |
+
|
| 131 |
+
```bash
|
| 132 |
+
python src/build_augmented_dataset.py --copies-per-image 4 --clean
|
| 133 |
+
```
|
| 134 |
|
| 135 |
### Training
|
| 136 |
|
| 137 |
+
Standard U-Net training:
|
| 138 |
+
|
| 139 |
+
```bash
|
| 140 |
+
python src/train.py \
|
| 141 |
+
--image-dir augmented_dataset/raw \
|
| 142 |
+
--mask-dir augmented_dataset/masks \
|
| 143 |
+
--epochs 40 --batch-size 4 --lr 1e-4 \
|
| 144 |
+
--image-size 256 --freeze-encoder-epochs 5
|
| 145 |
+
```
|
| 146 |
+
|
| 147 |
+
Area-consistency U-Net (LabelMe JSON polygons):
|
| 148 |
+
|
| 149 |
+
```bash
|
| 150 |
+
./trainenv/bin/python src/area_consistency/train_area.py
|
| 151 |
+
```
|
| 152 |
+
|
| 153 |
+
### Inference (CLI)
|
| 154 |
+
|
| 155 |
+
Single image:
|
| 156 |
+
|
| 157 |
+
```bash
|
| 158 |
+
python src/predict.py --input raw/your_image.jpg --weights models/best_finetuned.pt --output-dir predictions
|
| 159 |
+
```
|
| 160 |
+
|
| 161 |
+
Folder:
|
| 162 |
+
|
| 163 |
+
```bash
|
| 164 |
+
python src/predict.py --input raw --weights models/best_finetuned.pt --output-dir predictions
|
| 165 |
+
```
|
| 166 |
|
| 167 |
### Best Practices
|
| 168 |
|
| 169 |
+
- Keep trusted human-labelled masks unchanged.
|
| 170 |
+
- Use augmentations and area-consistency loss for improved generalisation.
|
| 171 |
- Inspect overlay outputs to verify mask quality.
|
| 172 |
+
- On Apple Silicon, MPS acceleration is used automatically if available.
|
| 173 |
|
| 174 |
+
---
|
| 175 |
|
| 176 |
+
## Demo Space
|
| 177 |
|
| 178 |
+
The full analysis pipeline is available as a Gradio Space:
|
| 179 |
|
| 180 |
+
**[`rotsl/grayleafspot-segmentation-demo`](https://huggingface.co/spaces/rotsl/grayleafspot-segmentation-demo)**
|
| 181 |
|
| 182 |
+
Features: dish detection β colony segmentation β crack & hyphae analysis β 16 morphometric measurements β time-series growth charts β CSV/JSON export.
|
| 183 |
|
| 184 |
+
Source code: [`rotsl/grayleafspot-segmentation-demo`](https://huggingface.co/rotsl/grayleafspot-segmentation-demo) (model repo)
|
| 185 |
|
| 186 |
+
---
|
| 187 |
+
|
| 188 |
+
## Citation
|
| 189 |
+
|
| 190 |
+
```bibtex
|
| 191 |
@misc{rohan_r_2026,
|
| 192 |
+
author = {rohan r},
|
| 193 |
+
title = {grayleafspot-segmentation (Revision 0e85f71)},
|
| 194 |
+
year = 2026,
|
| 195 |
+
url = {https://huggingface.co/rotsl/grayleafspot-segmentation},
|
| 196 |
+
doi = {10.57967/hf/8416},
|
| 197 |
+
publisher = {Hugging Face}
|
| 198 |
}
|
| 199 |
```
|
| 200 |
|
|
|
|
| 201 |
## License
|
| 202 |
|
| 203 |
+
Apache License 2.0 β see [LICENSE](LICENSE) for details.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|