Skip to main content

A simple, unified computer vision inference toolkit. One-liner API for common CV tasks.

Project description

anycv

anycv logo

PyPI Python License

A simple, unified computer vision inference toolkit. One-liner API for object detection, image classification, and semantic segmentation using ONNX Runtime.

Runs completely offline after first model download. Models are fetched from HuggingFace Hub once and cached locally in ~/.cache/anycv/. No cloud APIs required.

Built by Viet-Anh Nguyen at NRL.ai.

Installation

pip install anycv

For GPU support:

pip install anycv[gpu]

Quick Start

Object Detection

import anycv

detections = anycv.detect("photo.jpg")
for det in detections:
    print(f"{det.label}: {det.confidence:.2f} at {det.bbox}")

Image Classification

classes = anycv.classify("photo.jpg")
print(f"Top prediction: {classes[0].label} ({classes[0].confidence:.2%})")

Semantic Segmentation

seg = anycv.segment("photo.jpg")
print(f"Classes found: {seg.labels}")
# Access the pixel-level mask
mask = seg.mask  # (H, W) array of class IDs

Batch Processing

# Process multiple images at once
detections = anycv.detect(["img1.jpg", "img2.jpg", "img3.jpg"])

Flexible Image Input

import numpy as np
from PIL import Image

# All of these work:
anycv.detect("path/to/image.jpg")           # File path
anycv.detect(Path("image.png"))              # pathlib.Path
anycv.detect("https://example.com/img.jpg")  # URL
anycv.detect(np.zeros((480, 640, 3)))        # NumPy array
anycv.detect(Image.open("photo.jpg"))        # PIL Image

Available Models

Model Task Description
yolov8n Detection YOLOv8 Nano -- fast, 80 COCO classes
yolov8s Detection YOLOv8 Small -- balanced, 80 COCO classes
mobilenetv2 Classification MobileNetV2 -- lightweight, 1000 ImageNet classes
resnet50 Classification ResNet-50 -- accurate, 1000 ImageNet classes
deeplabv3 Segmentation DeepLabV3 -- 21 Pascal VOC classes
# List all available models
for model in anycv.list_models():
    print(f"{model.name:15s} {model.task:15s} {model.description}")

# Filter by task
det_models = anycv.list_models(task="detection")

Advanced Usage

Load and Reuse Models

model = anycv.load_model("yolov8n")
results1 = model(["img1.jpg", "img2.jpg"])
results2 = model("img3.jpg")

Custom Thresholds

detections = anycv.detect("photo.jpg", conf_threshold=0.5, iou_threshold=0.6)

Drawing Results

from anycv import load_image, draw_boxes

image = load_image("photo.jpg")
detections = anycv.detect(image)

boxes = [d.bbox for d in detections]
labels = [f"{d.label} {d.confidence:.0%}" for d in detections]
annotated = draw_boxes(image, boxes, labels=labels)

Local-First / Edge AI

This package is designed to work completely offline. After initial model download, no internet connection is required. All inference runs locally via ONNX Runtime on CPU, GPU, or edge devices.

# Pre-download all models for offline use
python -m anycv download

# Download only detection models
python -m anycv download --task detection
import anycv

# Pre-download everything
anycv.download_models()

# Download only classification models
anycv.download_models(task="classification")

Benchmarks

Model Input Size CPU (ms) GPU (ms)
yolov8n 640x640 TBD TBD
yolov8s 640x640 TBD TBD
mobilenetv2 224x224 TBD TBD
resnet50 224x224 TBD TBD
deeplabv3 513x513 TBD TBD

Development

git clone https://github.com/vietanhdev/anycv.git
cd anycv
pip install -e ".[dev]"
pytest tests/ -v

License

MIT License. See LICENSE for details.

Links

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

anycv-0.2.0.tar.gz (42.5 kB view details)

Uploaded Source

Built Distribution

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

anycv-0.2.0-py3-none-any.whl (34.1 kB view details)

Uploaded Python 3

File details

Details for the file anycv-0.2.0.tar.gz.

File metadata

  • Download URL: anycv-0.2.0.tar.gz
  • Upload date:
  • Size: 42.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for anycv-0.2.0.tar.gz
Algorithm Hash digest
SHA256 20193799c3a4b30d62cee5aa9f3a0002835d32b28d6a1bc28be9a6f833c5d1de
MD5 47a34a194eb69f08ef8a696ed6b0ba3f
BLAKE2b-256 894a21a1e70329f47b52c21cdcd81e493f46e00c60a88c9f6b190b5febf0c03d

See more details on using hashes here.

File details

Details for the file anycv-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: anycv-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 34.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for anycv-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a65c0dcfd424b9552feacc271e195055a2fc6f88203ee47142b6222a72de1044
MD5 8b3b11b5e4c973f688632b3ed85f1c78
BLAKE2b-256 95c5b2a20a6efa0900091ad55cd3bd428ac940021cf8f87cb892a9405a9a62a5

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