Skip to main content

BirdCrop 🐦✂️

BirdCrop is a Python command-line utility and library designed to automatically detect objects (like birds, people, etc.) in images using YOLO models and save cropped images of those detections. It offers flexible configuration for targeting specific classes, adding margins, sorting detections, and customizing output filenames and locations using powerful templating.

Originally developed to rapidly identify and extract avian subjects from high-speed burst photography, the system has since been expanded to support multiple and diverse object classes beyond birds. It excels in its primary application: processing large volumes of in-flight bird imagery where subjects occupy only a small pixel area within the frame. By automating detection and cropping workflows for burst sequences, the tool eliminates time-intensive manual adjustments like zooming and panning while retaining analytical accuracy, making it ideal for rapid wildlife surveys and high-throughput curation of still-image datasets.

Before (original folder)

image folder before auto-cropping

After Cropping (output folder)

image folder after auto-cropping

Key Features

  • YOLO-Powered Detection: Uses YOLO26 models by default for faster, more accurate bird detection. You can also provide a YOLOv8 or custom model with --model.
  • Flexible Class Targeting: Specify which object classes to detect using their names (e.g., "bird,dog,cat") or their model-specific IDs (e.g., "14,16,15"). The tool adapts to the classes present in the loaded model.
  • List Model Classes: Easily list all classes and their IDs available within a specific YOLO model file using the --list-classes option.
  • Customizable Output Paths: Define complex output file paths and names using Python's format string syntax via --output-template. Access detailed information about the input file, detection, and crop (see Template Variables below).
  • Cropping Margin: Add a specified pixel margin around the detected bounding box before cropping using --margin.
  • Detection Sorting: Sort multiple detections within an image by confidence or bounding box size (default) using --sortby.
  • Single or Multiple Crops: Choose to save only the single "best" detection (highest confidence or largest size) per image or save crops for all detected objects using --multiple.
  • Per-Category Numbering: Use the {pcnr} template variable for sequential numbering within each category for a given input image.
  • Directory Processing: Process all supported images within specified directories, optionally searching recursively (-r).
  • Concurrent Processing: Speed up processing on multi-core systems using parallel worker threads (-w).
  • Overwrite Control: Prevent accidental data loss by default; use --force (-f) to allow overwriting existing crop files.

Installation

Install the package and its runtime dependencies from PyPI:

python -m pip install bird-crop

For development from a checkout:

git clone https://github.com/variance/bird_crop.git
cd bird_crop
python -m pip install .

This installs the birdcrop library and the birdcrop and birdcrop-upgrade command-line commands. The legacy run_birdcrop.py and upgrade_birdcrop.py launchers remain available when running from a checkout.

BirdCrop uses yolo26n.pt by default. If the selected model is not present, the CLI downloads it automatically from the Ultralytics assets release. You can select another YOLO26 size with --model-size (nano, small, medium, large, or xlarge), or specify an existing YOLOv8/custom model with --model.

Model Selection

The default model is yolo26n.pt. Use --model-size to choose another YOLO26 model:

# default: yolo26n.pt
python run_birdcrop.py path/to/images

# use the large YOLO26 model
python run_birdcrop.py --model-size large path/to/images

# use a specific model file, including YOLOv8 or a custom model
python run_birdcrop.py --model path/to/model.pt path/to/images

When using --model-size, a missing model file is downloaded automatically. A user-specified --model must already exist locally.

Usage

The installed command is birdcrop:

birdcrop [options] [INPUT_PATH ...]

The equivalent checkout command is python run_birdcrop.py [options] [INPUT_PATH ...].

Update Checks

BirdCrop can check for upstream updates at startup.

CLI flags:

# enabled by default
python run_birdcrop.py --check-updates [options] [INPUT_PATH ...]

# disable all online checks
python run_birdcrop.py --no-update-check [options] [INPUT_PATH ...]

# network timeout per endpoint in seconds
python run_birdcrop.py --update-check-timeout 2.0 [options] [INPUT_PATH ...]

Upgrading

To keep BirdCrop and its YOLO models up to date, use the birdcrop-upgrade command:

# upgrade both the ultralytics package and download latest models
birdcrop-upgrade

# upgrade package only
birdcrop-upgrade --package-only

# download latest models only
birdcrop-upgrade --models-only

# download specific YOLO26 models
birdcrop-upgrade --models yolo26n.pt,yolo26l.pt

# download models to a specific directory
birdcrop-upgrade --output-dir ./models

# verbose output
birdcrop-upgrade --verbose

From a checkout, python upgrade_birdcrop.py remains an equivalent launcher.

The upgrade utility:

  • Updates ultralytics package via pip install --upgrade ultralytics
  • Downloads the latest YOLO model files from the latest ultralytics/assets release
  • Skips models that already exist locally (use --package-only or --models-only to update just one component)

Building and publishing

To build distributable artifacts locally:

python -m pip install build
python -m build

This creates a source distribution and wheel in dist/. After configuring your PyPI credentials, upload them with:

python -m pip install twine
python -m twine upload dist/*

Metadata

Release files for bird-crop 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bird-crop 0.1.5
File Size Uploaded Provenance Actions
bird_crop-0.1.5.tar.gz 21.4 kB Without provenance Details for bird_crop-0.1.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for bird-crop 0.1.5
File Interpreter ABI Platform Actions
bird_crop-0.1.5-py3-none-any.whl Python 3 none any Details for bird_crop-0.1.5-py3-none-any.whl

Total release size: 45.3 kB

Release files / bird_crop-0.1.5.tar.gz

Download URL bird_crop-0.1.5.tar.gz
Size 21.4 kB
Tags Source
SHA-256 checksum
How to use checksums
11b4d3541efc906dc639d0bb678c6c5b32bd196cc4b07df968427f584eaaeb1f
BLAKE2b-256 checksum
How to use checksums
269ba289ca6306e53ce4397f462c03ad4207a6800712f6e81c094e447ea9bbdc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release files / bird_crop-0.1.5-py3-none-any.whl

Download URL bird_crop-0.1.5-py3-none-any.whl
Size 24.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
655a1f388b355dc5e486bf5df58da82bbc40e9f1bb03f196a93d9a8ebad9bc49
BLAKE2b-256 checksum
How to use checksums
7cd1c6e51d08df82572a39786bd388a12629e49f39a33c8c787eef550dc6b72a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Security for bird-crop 0.1.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page