Skip to content

Train and evaluate a small butterfly localizer for photo crops - #83

Draft
mihow wants to merge 1 commit into
mainfrom
feat/leps-localizer-training
Draft

mihow wants to merge 1 commit into
mainfrom
feat/leps-localizer-training

Conversation

@mihow

@mihow mihow commented Sep 14, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Species classifiers do better when they see the butterfly rather than the whole photo. This PR adds the research code we used to train and compare small detectors that find the butterfly in a hand-held photo, so an upload flow or a classifier can crop to it. It compares YOLOv11s, YOLO26-s and -n, RT-DETR-l, DEIMv2-S and SAHI tiling, trained on Fieldguide photos with user-drawn crop boxes and evaluated on the public Leeds Butterfly dataset. The shared pieces (data reading, splitting, evaluation metrics) go in src/localization/ next to the existing Faster R-CNN tools; the experiment scripts and write-up go in research/leps_localizer/.

The branch was rewritten into a single commit on current main. Paths and service names are now command-line arguments or environment variables, so the scripts run on any machine.

List of Changes

Change Where
Train, evaluate, export and compare small butterfly detectors, with a methods and results write-up and a per-run results table research/leps_localizer/
A static browser demo and a guide for running the detector inside a photo upload page research/leps_localizer/demo/, EBUTTERFLY_INTEGRATION.md
Read the training index, repartition train/val deterministically, write YOLO datasets, and evaluate on a held-out set src/localization/leps_data.py, repartition.py, prepare_yolo.py, eval_locked.py
Best-of-N and containment metrics for single-subject photos src/localization/metrics.py
Unit tests for the modules above (37 pass) tests/localization/
Optional dependency groups detection, demo and export-edge, so the base install stays light pyproject.toml, uv.lock

Configuration comes from DATA_ROOT, RUNS_DIR, DETECTOR_DATASET_ROOT, CLASSIFIER_MODELS_DIR and, for Weights & Biases, WANDB_ENTITY.

Not included

Training images and the photo index are not part of the repository. The insect detector for light-trap photos (AnyBug) will follow in a separate PR.

🤖 Generated with Claude Code

https://claude.ai/code/session_014Sju2W91WevdNkZhTEGyqN

@coderabbitai

coderabbitai Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Add the research code for training and comparing small single-subject
detectors that find the butterfly in a photo, so that a species classifier
can crop to it. The work compares YOLOv11s, YOLO26-s/n, RT-DETR-l, DEIMv2-S
and SAHI tiling on a training set built from Fieldguide photos with
user-drawn crop boxes, and evaluates on the public Leeds Butterfly dataset.

What is included:

- research/leps_localizer/: training, evaluation, export and comparison
  scripts, the methods and results write-up with a per-run results table,
  a guide for embedding the browser build in a photo upload flow, and a
  static browser demo.
- src/localization/: an index reader for the training data, deterministic
  train/val repartitioning, YOLO dataset materialization, held-out
  evaluation, and best-of-N and containment metrics added to metrics.py.
- tests/localization/: unit tests for the modules above.
- pyproject.toml: new optional extras `detection`, `demo` and
  `export-edge`, plus flake8 per-file ignores for the new scripts; uv.lock
  regenerated.

This commit replaces the earlier feat/leps-localizer-training branch. That
branch carried internal infrastructure details (machine names, local and
mounted paths, storage and warehouse names, private repository references,
and session notes) and a data index of individual photo records. Those are
removed here: paths are now command-line arguments or environment variables
(DATA_ROOT, RUNS_DIR, DETECTOR_DATASET_ROOT, CLASSIFIER_MODELS_DIR), the
Weights & Biases entity comes only from WANDB_ENTITY, and the bulk
annotation scripts and internal schemas are left out. Unrelated changes
that the earlier branch had merged in from other branches are not part of
this commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014Sju2W91WevdNkZhTEGyqN
@mihow
mihow force-pushed the feat/leps-localizer-training branch from efd64f2 to 0e37df3 Compare October 14, 2026 20:07
@mihow mihow changed the title [Draft] Localizer training pipeline Train and evaluate a small butterfly localizer for photo crops Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant