Skip to main content

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

Project description

anycv

Computer vision in one line of code

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.1.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.1-py3-none-any.whl (34.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: anycv-0.2.1.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.1.tar.gz
Algorithm Hash digest
SHA256 3dfd5b7c0193d7894440e854cfdffe71bf0eed14066d553045c8727a1c119cc4
MD5 d9a20c14380b115df443cca0097a6947
BLAKE2b-256 aaadfc6a48186e8230ad3a88975279650a818648537a865735304750c8a76877

See more details on using hashes here.

File details

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

File metadata

  • Download URL: anycv-0.2.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2aa4db8a7064265f431fc83a8c413a444f16969e2590855d8e3d7ffe93f18fdd
MD5 f70ee0e5ae4c025d910143f231af37c7
BLAKE2b-256 cbb4a20b7a59aa58af16d441bf04fb802d55c1cb545391cd9f92b6066611ed21

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