Skip to main content

flatbug

A General Method for Detection and Segmentation of Terrestrial Arthropods in Images

Open In Colab

PyPI version Python Versions CI Status Code style: ruff License: MIT

Find and cite the flatbug paper in Method in Ecology and Evolution Send us new data through our data contribution form.

flatbug is partly a high-performance pyramid tiling inference wrapper for YOLOv8 and partly a hybrid instance segmentation dataset of terrestrial arthropods accompanied by an appropriate training schedule for YOLOv8 segmentation models, built on top of the original YOLOv8 training schedule.

The goal of flatbug is to provide a single unified model for detection and segmentation of all terrestrial arthropods on arbitrarily large images, especially fine-tuned for the case of top-down images/scans - thus the name "flat"bug.


Installation

We recommend using uv (installation):

# Install
uv pip install flat-bug --torch-backend=auto
# Add to a project permanently
uv add flat-bug

[!TIP] If you have problems with PyTorch not being installed with CUDA enabled try:

uv pip install torch torchvision --torch-backend=auto --reinstall

More details: https://docs.astral.sh/uv/guides/integration/pytorch/#the-uv-pip-interface

or (not recommended):

pip install flat-bug

Source/development

Or a development version can be installed from source by cloning this repository:

Clone the repository

git clone https://github.com/darsa-group/flat-bug.git
cd flat-bug

Install flatbug

uv sync --all-extras --all-groups --upgrade 
# (optional but recommended)
uv pip install torch torchvision --torch-backend=auto --reinstall

or (not recommended):

pip install -e .

[!WARNING] If you do decide to install with pip, as with other packages built with PyTorch it is best to ensure that torch is installed separately. See https://pytorch.org/ for details. We recommend using torch>=2.3.


CLI Usage

We provide a number of CLI scripts with flatbug. The main one of interest is fb_predict, which can be used to run inference on images or videos:

[uv run] fb_predict -i <DIR_WITH_IMGS> -o <OUTPUT_DIR> [-w <WEIGHT_PATH>] ...

Tutorials

We provide a number of tutorials on general and advanced usage, training, deployment and hyperparameters of flatbug in examples/tutorials or with Google Colab Open In Colab.

Documentation

Find our documentation at https://darsa.info/flat-bug/.


CUDA Issues

Working with cross-platform PyTorch code can be a bit confusing, so if you ever get stuck with some CUDA errors, here are some possible paths to resolve the issues.

uv and pip

If you installed flat-bug via a package manager but find that GPU acceleration is not working, your environment likely downloaded the default PyPI wheels which may not match your system's NVIDIA drivers.

If you are using uv, the easiest fix is to force a re-resolution of the PyTorch backend:

# Automatically detect hardware and reinstall PyTorch
uv pip install torch torchvision --torch-backend=auto --reinstall

# OR manually force a specific CUDA version (e.g., CUDA 11.8)
uv pip install torch torchvision --torch-backend=cu118 --reinstall

If you are using standard pip, you must manually point to the PyTorch index that matches your system:

# Uninstall the broken versions
pip uninstall torch torchvision

# Reinstall pointing explicitly to the CUDA 11.8 or 12.1 (cu121) index
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu118

Verification:

[uv run] python -c "import torch; print(f'CUDA Available: {torch.cuda.is_available()}')"

Source

Rebuild the environment and lockfile from scratch:

# cd ~/flat-bug

# 1. Purge old state
rm uv.lock
rm -rf .venv

# 2. Generate the pure, cross-platform lockfile
uv lock

# 3. Create your local environment
uv sync --all-extras --all-groups

# 4. Patch your local environment with your specific hardware backend
uv pip install torch torchvision --torch-backend=auto --reinstall

Download files

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

Source Distribution

flat_bug-1.2.0.tar.gz (106.3 kB view details)

Uploaded Source

Built Distribution

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

flat_bug-1.2.0-py3-none-any.whl (115.3 kB view details)

Uploaded Python 3

File details

Details for the file flat_bug-1.2.0.tar.gz.

File metadata

  • Download URL: flat_bug-1.2.0.tar.gz
  • Upload date:
  • Size: 106.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.27 {"installer":{"name":"uv","version":"0.11.27","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for flat_bug-1.2.0.tar.gz
Algorithm Hash digest
SHA256 fe55b229b2a67ed6d88e673f8ae9814185a63534646b17c14646e3f89a6babab
MD5 87b3b3060d4a4437b618f77f26ba75db
BLAKE2b-256 5ca742fbdbf14f42d8a57f4a275dcd1c236896d9657fc7d8dcee3f808397a957

See more details on using hashes here.

File details

Details for the file flat_bug-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: flat_bug-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 115.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.27 {"installer":{"name":"uv","version":"0.11.27","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for flat_bug-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cc92d618ac8b516b6e505cb6d49683a5ea57ca1b293f5fa68bc98f7493c16b84
MD5 aa884ce07e82b4682b16df004c3bb5b7
BLAKE2b-256 383b523e149b61f3d1e778a562b38c72f2fe18753a9aa2439eaadd86e92b1a84

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 files

1.1.2

2 files

1.1.1

2 files

1.1.0

2 files

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