Skip to main content

Train custom bird species classifiers from video footage

Project description

๐Ÿฆ Vogel Model Trainer

Languages: ๐Ÿ‡ฌ๐Ÿ‡ง English | ๐Ÿ‡ฉ๐Ÿ‡ช Deutsch

PyPI version Python Versions License: MIT PyPI Status Downloads

Train custom bird species classifiers from your own video footage using YOLOv8 and EfficientNet.

A specialized toolkit for creating high-accuracy bird species classifiers tailored to your specific monitoring setup. Extract training data from videos, organize datasets, and train custom models with >96% accuracy.


โœจ Features

  • ๐ŸŽฏ YOLO-based Bird Detection - Automated bird cropping from videos using YOLOv8
  • ๐Ÿค– Three Extraction Modes - Manual labeling, auto-sorting, or standard extraction
  • ๐Ÿ“ Wildcard Support - Batch process multiple videos with glob patterns
  • ๐Ÿ–ผ๏ธ Auto-Resize to 224x224 - Optimal image size for training
  • ๐Ÿง  EfficientNet-B0 Training - Lightweight yet powerful classification model
  • ๐ŸŽจ Enhanced Data Augmentation - Rotation, affine transforms, color jitter, gaussian blur
  • ๐Ÿ“Š Optimized Training - Cosine LR scheduling, label smoothing, early stopping
  • โธ๏ธ Graceful Shutdown - Save model state on Ctrl+C interruption
  • ๐Ÿ”„ Iterative Training - Use trained models to expand your dataset
  • ๐Ÿ“ˆ Per-Species Metrics - Detailed accuracy breakdown by species

๐Ÿš€ Quick Start

Installation

# Install from PyPI
pip install vogel-model-trainer

# Or install from source
git clone https://github.com/kamera-linux/vogel-model-trainer.git
cd vogel-model-trainer
pip install -e .

Basic Workflow

# 1. Extract bird images from videos
vogel-trainer extract video.mp4 --bird great-tit --output ~/training-data/

# 2. Organize into train/validation split
vogel-trainer organize --source ~/training-data/ --output ~/training-data/organized/

# 3. Train custom classifier
vogel-trainer train --data ~/training-data/organized/ --output ~/models/

# 4. Test the trained model
vogel-trainer test ~/models/final/ test_image.jpg

๐Ÿ“– Usage Guide

1. Extract Training Images

Manual Mode (Recommended for Initial Collection)

When you know the species in your video:

vogel-trainer extract ~/Videos/great-tit-*.mp4 \
  --bird great-tit \
  --output ~/training-data/ \
  --threshold 0.5 \
  --sample-rate 3

Auto-Sort Mode (For Iterative Training)

Use an existing model to automatically classify and sort:

vogel-trainer extract ~/Videos/mixed-*.mp4 \
  --species-model ~/models/classifier/final/ \
  --output ~/training-data/ \
  --threshold 0.6

Batch Processing with Wildcards

# Process all videos in a directory
vogel-trainer extract "~/Videos/*.mp4" --bird blue-tit --output ~/data/

# Recursive directory search
vogel-trainer extract ~/Videos/ \
  --species-model ~/models/classifier/final/ \
  --output ~/data/ \
  --recursive

Parameters:

  • --threshold: YOLO confidence threshold (default: 0.5)
  • --sample-rate: Process every Nth frame (default: 3)
  • --bird: Manual species label
  • --species-model: Path to trained model for auto-classification
  • --no-resize: Keep original image size (default: resize to 224x224)

2. Organize Dataset

vogel-trainer organize \
  --source ~/training-data/ \
  --output ~/training-data/organized/ \
  --train-ratio 0.8

Creates an 80/20 train/validation split:

organized/
โ”œโ”€โ”€ train/
โ”‚   โ”œโ”€โ”€ great-tit/
โ”‚   โ”œโ”€โ”€ blue-tit/
โ”‚   โ””โ”€โ”€ robin/
โ””โ”€โ”€ val/
    โ”œโ”€โ”€ great-tit/
    โ”œโ”€โ”€ blue-tit/
    โ””โ”€โ”€ robin/

3. Train Classifier

vogel-trainer train \
  --data ~/training-data/organized/ \
  --output ~/models/ \
  --epochs 50 \
  --batch-size 16

Training Configuration:

  • Base Model: google/efficientnet-b0 (8.5M parameters)
  • Optimizer: AdamW with cosine LR schedule
  • Augmentation: Rotation, affine, color jitter, gaussian blur
  • Regularization: Weight decay 0.01, label smoothing 0.1
  • Early Stopping: Patience of 7 epochs

Output:

~/models/bird-classifier-20251108_143000/
โ”œโ”€โ”€ checkpoints/     # Intermediate checkpoints
โ”œโ”€โ”€ logs/           # TensorBoard logs
โ””โ”€โ”€ final/          # Final trained model
    โ”œโ”€โ”€ config.json
    โ”œโ”€โ”€ model.safetensors
    โ””โ”€โ”€ preprocessor_config.json

4. Test Model

# Test on single image
vogel-trainer test ~/models/final/ image.jpg

# Output:
# ๐Ÿ–ผ๏ธ  Testing: image.jpg
#    ๐Ÿฆ Predicted: great-tit (98.5% confidence)

๐Ÿ”„ Iterative Training Workflow

Improve your model by iteratively expanding your dataset:

# 1. Initial training with manual labels
vogel-trainer extract ~/Videos/batch1/*.mp4 --bird great-tit --output ~/data/
vogel-trainer organize --source ~/data/ --output ~/data/organized/
vogel-trainer train --data ~/data/organized/ --output ~/models/v1/

# 2. Use trained model to extract more data
vogel-trainer extract ~/Videos/batch2/*.mp4 \
  --species-model ~/models/v1/final/ \
  --output ~/data/iteration2/

# 3. Review and correct misclassifications manually
# Move incorrect predictions to correct species folders

# 4. Combine datasets and retrain
cp -r ~/data/iteration2/* ~/data/
vogel-trainer organize --source ~/data/ --output ~/data/organized/
vogel-trainer train --data ~/data/organized/ --output ~/models/v2/

# Result: Higher accuracy! ๐ŸŽ‰

๐Ÿ“Š Performance & Best Practices

Dataset Size Recommendations

Quality Images per Species Expected Accuracy
Minimum 20-30 ~85-90%
Good 50-100 ~92-96%
Optimal 100+ >96%

Tips for Better Results

  1. Dataset Diversity

    • Include various lighting conditions
    • Capture different poses (side, front, back)
    • Cover different seasons (plumage changes)
  2. Class Balance

    • Aim for similar image counts per species
    • Avoid having one dominant class
  3. Quality Over Quantity

    • Use threshold 0.5-0.6 for clear detections
    • Manual review of auto-sorted images improves quality
  4. Monitor Training

    • Check per-class accuracy for weak species
    • Use confusion matrix to identify similar species
    • Add more data for low-performing classes

๐Ÿ”— Integration with vogel-video-analyzer

Use your trained model for species identification:

vogel-analyze --identify-species \
  --species-model ~/models/final/ \
  --species-threshold 0.3 \
  video.mp4

๐Ÿ› ๏ธ Development

# Clone repository
git clone https://github.com/kamera-linux/vogel-model-trainer.git
cd vogel-model-trainer

# Install in development mode
pip install -e ".[dev]"

# Run tests
pytest tests/

๐Ÿ“ License

MIT License - see LICENSE for details.


๐Ÿ™ Credits


๐Ÿ“ฎ Support & Contributing


Made with โค๏ธ for bird watching enthusiasts ๐Ÿฆ

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vogel_model_trainer-0.1.0.tar.gz (34.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vogel_model_trainer-0.1.0-py3-none-any.whl (22.9 kB view details)

Uploaded Python 3

File details

Details for the file vogel_model_trainer-0.1.0.tar.gz.

File metadata

  • Download URL: vogel_model_trainer-0.1.0.tar.gz
  • Upload date:
  • Size: 34.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for vogel_model_trainer-0.1.0.tar.gz
Algorithm Hash digest
SHA256 eb17d297063c48fbe906d5606d0394ee3f8987eb26c1e18e8723de0bf4724671
MD5 43d41b2406a4235a9666866c4297170c
BLAKE2b-256 da8a0fc19fb80b3931f7b9c047e8d071602981d3a3d035177929117773e6e22c

See more details on using hashes here.

File details

Details for the file vogel_model_trainer-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for vogel_model_trainer-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bbf29105254b9bc14a1d060c47857a7d84240f6c64a35de07ade73a8bdd47e7e
MD5 23dfdbfdb6d913ac58d18d6f6a7ba269
BLAKE2b-256 c380ee21e2dd98f3c0430c866f55372f887d533b1d0a28d0b6edcb603792f42b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page