Skip to main content

Universal Arthropod Localization and Instance Segmentation

Project description

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

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

flat_bug-1.1.2.tar.gz (106.9 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.1.2-py3-none-any.whl (115.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: flat_bug-1.1.2.tar.gz
  • Upload date:
  • Size: 106.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.13 {"installer":{"name":"uv","version":"0.11.13","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.1.2.tar.gz
Algorithm Hash digest
SHA256 7b79bf1bc379d0465d63ae07afd25cf4ecf7a8511428f58aed86862523c46a9c
MD5 ecf7050097688b06385dba629bc9625f
BLAKE2b-256 483e75885d1b96349b3fe5094489ca59e4d90ce4b5c21883262ba9ae5dea0af6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: flat_bug-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 115.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.13 {"installer":{"name":"uv","version":"0.11.13","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.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 93a9bdf757ae2529361cae3a83e5dc46c0172928cbba34c70369b70a438c400d
MD5 cd95acceb61dd7f9eea7da7797b393d6
BLAKE2b-256 5273af4cd3f8e6646e4ab3566e115a826bed0334d4c8155b56fe214d872dc001

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