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.
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
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file anycv-0.2.3.tar.gz.
File metadata
- Download URL: anycv-0.2.3.tar.gz
- Upload date:
- Size: 43.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee6ecd82fdabc6d552d26b04c3823eb4dbb16fa7d4ae5254c94e8ed2887e8e8c
|
|
| MD5 |
4aafdca5aa08bcfdb532d541a0cced31
|
|
| BLAKE2b-256 |
abcd7f992d478e9e0ca5e67fc79f90227c5395a82a6a1ef2cb91ef3f67fd657e
|
File details
Details for the file anycv-0.2.3-py3-none-any.whl.
File metadata
- Download URL: anycv-0.2.3-py3-none-any.whl
- Upload date:
- Size: 34.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e8a9232ddcccc9c27a6722118777dd0c80715d72a97949d14f89bb2c744c8dc3
|
|
| MD5 |
a1a31ecd9ffe1d31037646500481eda7
|
|
| BLAKE2b-256 |
54231bf03589dfeb2af9f2246c8fa536073b08fbff9b5a773397d0edf19bcfec
|