Skip to main content

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 API — anycv.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

Release files for anycv 0.2.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for anycv 0.2.4
File Size Uploaded
anycv-0.2.4.tar.gz 44.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for anycv 0.2.4
File Interpreter ABI Platform
anycv-0.2.4-py3-none-any.whl Python 3 none any Details

Total release size: 81.1 kB

Release files / anycv-0.2.4.tar.gz

Download URL anycv-0.2.4.tar.gz
Size 44.8 kB
Tags Source
SHA-256 checksum
How to use checksums
0b5a04e028fbafc919fc5b3e34baaaffd44a8eb57ca5c0e3596e2846ed9caf98
BLAKE2b-256 checksum
How to use checksums
1219a677fc74b20c38db1e963c560ca0bbe9e9b0ddeb88dd4d425debedb434f9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.9

Release files / anycv-0.2.4-py3-none-any.whl

Download URL anycv-0.2.4-py3-none-any.whl
Size 36.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2a4b4acf1261caf634abd4ca38c3b3cecddfb8cb9e77db85ca21ecc4c2d67552
BLAKE2b-256 checksum
How to use checksums
1de6687a06c97eaabf457768a5b12a9544f33c275bf04a7db3a012ffa0f3fe03
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.9

Release history Release notifications | RSS feed

This release

0.2.4 This release

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page