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

# Runs YOLOv8n object detection via ONNX Runtime
# Model auto-downloads from HuggingFace Hub (~6MB), cached in ~/.cache/anycv/
# Returns Detection(bbox, label, confidence) for each detected object
detections = anycv.detect("photo.jpg")
for det in detections:
    print(f"{det.label}: {det.confidence:.2f} at {det.bbox}")

Image Classification

# Runs MobileNetV2 classification via ONNX Runtime (~14MB model)
# Preprocesses image to 224x224, normalizes with ImageNet mean/std
# Returns top-k ClassificationResult(label, confidence) from 1000 ImageNet classes
classes = anycv.classify("photo.jpg")
print(f"Top prediction: {classes[0].label} ({classes[0].confidence:.2%})")

Semantic Segmentation

# Runs DeepLabV3 segmentation via ONNX Runtime
# Produces a per-pixel class map over 21 Pascal VOC categories
# Returns SegmentationResult with .labels (classes found) and .mask (H, W array)
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.2.tar.gz (42.7 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.2-py3-none-any.whl (34.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: anycv-0.2.2.tar.gz
  • Upload date:
  • Size: 42.7 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.2.tar.gz
Algorithm Hash digest
SHA256 06877413541e877eadcb3979d0cd408901d22f68f1e123daacdfd378bb7d33c2
MD5 131f536e0b0a1c58b409e93c5f5eaf5c
BLAKE2b-256 64415d87d29f0d6c68f5488b82e628d29516753c9e8e15c69e35ee15597cef9d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: anycv-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 34.3 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 746c66842656bc4780713ddaf4abc9b4041acf67d15a1bcde6cb4143af8cf773
MD5 3bade50f39d59fa7a7d53c08946517e4
BLAKE2b-256 44f2b64c3b9b1e723929011b86eb9205b4adbc41500f70cb5c7de354bbcb74da

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