Skip to main content

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

Project description

anycv

One-liner computer vision — detect, classify, and segment in 3 lines of code.

PyPI Python License

anycv is a dead-simple computer vision inference library. It wraps the most popular pretrained models (YOLOv8 for detection, MobileNetV2/ResNet50 for classification, DeepLabV3 for segmentation) behind a one-liner API. Models are executed via ONNX Runtime for fast CPU inference (or GPU if available), auto-downloaded from Hugging Face Hub on first use, and cached locally. No PyTorch required at inference time.

Built by Viet-Anh Nguyen at NRL.ai.

Why anycv?

  • One-liner APIanycv.detect("photo.jpg") returns bounding boxes immediately
  • Plugin architecture — Register custom backends (TensorRT, OpenVINO, VLMs) via @register_backend
  • Local-first — Models cached in ~/.cache/anycv/, zero network after first run
  • Minimal core deps — Only onnxruntime, pillow, numpy; PyTorch is optional
  • Production-ready — Type hints, dataclass results, streaming, batch inference

Installation

pip install anycv

For optional features:

pip install anycv[gpu]       # onnxruntime-gpu for CUDA inference
pip install anycv[torch]     # use PyTorch models directly
pip install anycv[vlm]       # Vision-LLM backend via anyllm (GPT-4o, Claude)
pip install anycv[all]       # everything

Python 3.8+ supported (tested on 3.8, 3.9, 3.10, 3.11, 3.12, 3.13)

Quick Start

import anycv

# 1. Object detection (YOLOv8n via ONNX Runtime — auto-downloaded from HF Hub)
detections = anycv.detect("street.jpg", model="yolov8n")
for d in detections:
    print(d.label, d.confidence, d.bbox)  # e.g. "person" 0.92 (x1,y1,x2,y2)

# 2. Image classification (MobileNetV2 ImageNet-1k via ONNX Runtime)
result = anycv.classify("cat.jpg", model="mobilenetv2")
print(result.top_k(5))                   # [(label, prob), ...]

# 3. Semantic segmentation (DeepLabV3 Pascal-VOC via ONNX Runtime)
mask = anycv.segment("scene.jpg", model="deeplabv3")
mask.save("mask.png")                    # per-pixel class map

Models & Methods

All models are distributed as ONNX files, auto-downloaded from Hugging Face Hub on first use and cached in ~/.cache/anycv/. Inference runs on ONNX Runtime (CPU by default; GPU via onnxruntime-gpu).

Object Detection

Model Dataset Size Notes
yolov8n (default) COCO (80 classes) ~6 MB Fastest, ~10ms on CPU
yolov8s COCO (80 classes) ~22 MB Balanced
yolov8m COCO (80 classes) ~50 MB Higher accuracy

Exported from Ultralytics YOLOv8.

Image Classification

Model Dataset Size Notes
mobilenetv2 (default) ImageNet-1k ~14 MB Fast, mobile-friendly
resnet50 ImageNet-1k ~98 MB Higher accuracy

Semantic Segmentation

Model Dataset Classes Notes
deeplabv3 Pascal VOC 2012 21 Classic segmentation baseline

Vision-LLM Backend (optional)

When installed with anycv[vlm], you can use multi-modal LLMs for detection/classification via natural-language prompts:

# Uses anyllm to call GPT-4o, Claude 3.5 Sonnet, Gemini, or local LLaVA
result = anycv.classify("x-ray.jpg", backend="vlm", model="gpt-4o",
                        prompt="Classify findings: normal, pneumonia, or other")

Preprocessing pipeline

Every backend applies: letterbox resize -> BGR/RGB normalization -> mean/std standardization -> NCHW transpose. All handled automatically.

API Reference

Function Purpose
anycv.detect(image, model="yolov8n", conf=0.25) Returns List[Detection]
anycv.classify(image, model="mobilenetv2") Returns Classification
anycv.segment(image, model="deeplabv3") Returns SegmentationMask
anycv.list_models(task="detect") List available models
anycv.load_model(name) Preload a model (warm cache)
anycv.register_backend(name, cls) Register a custom backend
anycv.draw(image, detections) Visualize results on the image

Result dataclasses

@dataclass
class Detection:
    label: str
    confidence: float
    bbox: tuple[float, float, float, float]  # x1, y1, x2, y2
    class_id: int

CLI Usage

anycv detect street.jpg --model yolov8n --conf 0.3 --save annotated.jpg
anycv classify cat.jpg --top 5
anycv segment scene.jpg --out mask.png
anycv list-models

Examples

Batch inference over a folder

import anycv
from pathlib import Path

# Load once, reuse across images (warm model, no reload)
model = anycv.load_model("yolov8s")
for img in Path("images/").glob("*.jpg"):
    dets = model.detect(img, conf=0.4)
    print(img.name, len(dets), "objects")

Use a custom confidence + visualization

import anycv

dets = anycv.detect("crowd.jpg", model="yolov8m", conf=0.5)
annotated = anycv.draw("crowd.jpg", dets)   # Pillow image with boxes
annotated.save("out.jpg")

Register a custom backend

from anycv import register_backend, BaseDetector

@register_backend("detect", "my_tensorrt")
class TensorRTDetector(BaseDetector):
    def predict(self, image): ...

anycv.detect("photo.jpg", model="my_tensorrt")

License

MIT (c) Viet-Anh Nguyen

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.4.tar.gz (44.8 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.4-py3-none-any.whl (36.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: anycv-0.2.4.tar.gz
  • Upload date:
  • Size: 44.8 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.4.tar.gz
Algorithm Hash digest
SHA256 0b5a04e028fbafc919fc5b3e34baaaffd44a8eb57ca5c0e3596e2846ed9caf98
MD5 1933e4b3dc07e97a668af06b57f626c9
BLAKE2b-256 1219a677fc74b20c38db1e963c560ca0bbe9e9b0ddeb88dd4d425debedb434f9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: anycv-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 36.2 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 2a4b4acf1261caf634abd4ca38c3b3cecddfb8cb9e77db85ca21ecc4c2d67552
MD5 f0ae289c0e327ef4970fcc15ad597530
BLAKE2b-256 1de6687a06c97eaabf457768a5b12a9544f33c275bf04a7db3a012ffa0f3fe03

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