hotsight's picture
Fix relative paths after the PseudoLabeling/ move and stale split-file names in docs
490858f verified
|
Raw History Blame Contribute Delete
6.27 kB
# Automatic RGB+IR Labeling Tool
Generates per-pixel label annotations for registered RGB/IR wildfire footage
(the layout of `../../Data/`, the hand-labeled data at the root of this repository). A trained YOLO detector and IR hotspot thresholding propose
candidate regions, and SAM turns those proposals into per-pixel masks. You give
it a dataset folder; for each RGB/IR frame pair it writes a label mask in the same format
as the dataset's own `mask/` files, plus overlay images.
## What you need
1. **This folder**, unzipped anywhere. It already contains the trained models, nothing
else to download:
- `auto_annotate.py`: the tool
- `weights/best.pt`: trained detector
- `sam_vit_b_01ec64.pth`: segmentation model
- `requirements.txt`
Keep `auto_annotate.py` inside this folder. It finds the models by their path
relative to the script, not to your working directory. If you move it, pass
`--weights` and `--sam-checkpoint` explicitly.
2. **Your data** (not included), in the layout described under
"Running on your own data" below. For the original dataset, point
at the folder that directly contains `Canopy/` and `Graminoid/`, which in this
repository is `../../Data` relative to this folder.
3. **Python 3.10+**:
```bash
pip install -r requirements.txt
```
If the machine has an NVIDIA GPU, install the CUDA build of torch as well. This is about
2x faster (roughly 14 s per frame instead of 25-35 s). The `--force-reinstall` matters:
without it pip sees the CPU build already installed and does nothing.
```bash
pip install --force-reinstall torch torchvision --index-url https://download.pytorch.org/whl/cu126
```
Verify it worked: the tool prints `PyTorch <version> | CUDA: True` on startup. If it says
`CUDA: False`, it is running on CPU.
## How to run
You must pass exactly one of `--split`, `--clip` or `--all`.
Everything in the dataset's train + test splits (775 pairs, about 3 hours on a GPU, 6-8
hours on CPU):
```bash
python auto_annotate.py --dataset ../../Data --split train test --out MyAnnotations
```
One clip (`--clip` is repeatable), or specific frames of it:
```bash
python auto_annotate.py --dataset path/to/dataset --clip Graminoid-08 --out MyAnnotations
python auto_annotate.py --dataset path/to/dataset --clip Graminoid-08 --frames f00300 f00600 --out MyAnnotations
```
Every clip found in the folder:
```bash
python auto_annotate.py --dataset path/to/dataset --all --out MyAnnotations
```
Other options:
- `--split` accepts `train`, `val`, `test` (any combination). It reads the frame list
from `samples_splits.csv` at the dataset root, the annotators' working file, which is not
part of this release. On the released `../../Data/` use `--clip` or `--all` instead.
- Interrupted run? Just run the same command again; finished frames are skipped. Use
`--overwrite` to redo them.
- `--no-copy-inputs` skips copying the rgb/ir frames into the output. This saves about
6 GB on a full run; the homography is still copied.
- `--class-thr T1 T2 T3 T4 T5` overrides the per-class confidence thresholds. Defaults are
`0.25 0.35 0.45 0.45 0.45`. Passing `0.25 0.25 0.45 0.45 0.45` lowers only class 2
(class 1 is already at 0.25); on held-out validation clips this improved class-2
detection with no measured loss on the other classes.
## What you get
One folder per clip, following the dataset layout, with one addition (`mask_color/`,
which the dataset does not ship) and one omission (`ir_gray/`, which this tool does not
produce):
```
MyAnnotations/<Unit>/<Clip>/
mask/fNNNNN.txt the label mask (see format below)
mask_overlay/fNNNNN.jpg labels blended over the RGB frame, for eyeballing
mask_color/fNNNNN.png labels as a flat color image
rgb/, ir/, homography/ copies of the inputs, so each output clip folder loads
standalone in the dataset's own viewer.html
(`../../html/viewer.html` in this repository)
```
**Mask format:** exactly 2688 x 1512 = 4,064,256 ASCII digit bytes. One digit per pixel,
values 1-5, row-major, single line, no newline and no separators. Identical to the
dataset's own mask files. To read one:
```python
import numpy as np
with open("mask/f00300.txt", "rb") as f:
mask = (np.frombuffer(f.read(), dtype=np.uint8) - ord("0")).reshape(1512, 2688)
```
Classes: 1 = red, 2 = orange, 3 = yellow, 4 = green, 5 = black. Every pixel gets one of
the five; there is no "unlabeled" value.
**Disk space:** about 13 MB per frame with input copies (10 GB for a 775-frame run), or
about 5.3 MB per frame with `--no-copy-inputs`.
## Running on your own data
The tool needs, per clip:
```
<root>/<Unit>/<Clip>/rgb/fNNNNN.png RGB frame
<root>/<Unit>/<Clip>/ir/fNNNNN.png IR frame, same filename as its RGB partner
<root>/<Unit>/<Clip>/homography/homography.json
```
Two things that commonly go wrong:
- **The IR frames must be the colorized IR**, not grayscale. The hotspot step
thresholds red and white; grayscale IR silently yields no hotspots.
- **Filenames must match exactly** between `rgb/` and `ir/`. A frame with no IR partner is
reported and skipped.
`homography.json` maps IR pixels to RGB pixels:
```json
{
"ir_size": [640, 360],
"rgb_size": [2688, 1512],
"maps": "IR_pixel -> RGB_pixel",
"subsets": [
{
"label": "f00300-f02400",
"frame_start": "f00300.png",
"frame_end": "f02400.png",
"matrix": [[3.134, -0.049, 308.2], [-0.017, 3.044, 223.4], [-4.2e-05, -4.2e-05, 1]]
}
]
}
```
Use several `subsets` if the registration changes during the clip; the tool picks the one
whose frame range covers each frame (nearest range if none does).
## Accuracy, please read
The output is generated by the pipeline, not human ground truth. Quality varies
between clips and classes. Always spot-check `mask_overlay/` before treating any output
as ground truth.
## Good to know
- Frames are skipped in two cases: no IR partner, or no detection survives the confidence
thresholds (nothing to segment). Both are reported.
- The IR-to-RGB registration is read from `homography.json`; the tool never computes or
refines it.
- A failed frame never aborts the run; it is reported and the run continues.