Metadata-Version: 2.4
Name: anycv
Version: 0.2.1
Summary: A simple, unified computer vision inference toolkit. One-liner API for common CV tasks.
Project-URL: Homepage, https://www.nrl.ai
Project-URL: Repository, https://github.com/vietanhdev/anycv
Project-URL: Issues, https://github.com/vietanhdev/anycv/issues
Author-email: Viet-Anh Nguyen <vietanh.dev@gmail.com>
License-Expression: MIT
License-File: LICENSE
Keywords: classification,computer-vision,detection,inference,onnx,segmentation
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Scientific/Engineering :: Image Recognition
Requires-Python: >=3.8
Requires-Dist: click>=8.0
Requires-Dist: huggingface-hub
Requires-Dist: numpy
Requires-Dist: onnxruntime
Requires-Dist: pillow
Requires-Dist: requests
Provides-Extra: all
Requires-Dist: anyllm>=0.1.0; extra == 'all'
Requires-Dist: onnxruntime-gpu; extra == 'all'
Requires-Dist: opencv-python>=4.5.0; extra == 'all'
Provides-Extra: benchmark
Requires-Dist: numpy; extra == 'benchmark'
Provides-Extra: dev
Requires-Dist: pytest; extra == 'dev'
Requires-Dist: pytest-cov; extra == 'dev'
Provides-Extra: gpu
Requires-Dist: onnxruntime-gpu; extra == 'gpu'
Provides-Extra: llm
Requires-Dist: anyllm>=0.1.0; extra == 'llm'
Provides-Extra: progress
Requires-Dist: tqdm; extra == 'progress'
Provides-Extra: video
Requires-Dist: opencv-python>=4.5.0; extra == 'video'
Description-Content-Type: text/markdown

<h1 align="center">anycv</h1>
<p align="center"><em>Computer vision in one line of code</em></p>

![PyPI](https://img.shields.io/pypi/v/anycv)
![Python](https://img.shields.io/pypi/pyversions/anycv)
![License](https://img.shields.io/pypi/l/anycv)

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](https://github.com/vietanhdev) at [NRL.ai](https://www.nrl.ai).

## Installation

```bash
pip install anycv
```

For GPU support:

```bash
pip install anycv[gpu]
```

## Quick Start

### Object Detection

```python
import anycv

detections = anycv.detect("photo.jpg")
for det in detections:
    print(f"{det.label}: {det.confidence:.2f} at {det.bbox}")
```

### Image Classification

```python
classes = anycv.classify("photo.jpg")
print(f"Top prediction: {classes[0].label} ({classes[0].confidence:.2%})")
```

### Semantic Segmentation

```python
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

```python
# Process multiple images at once
detections = anycv.detect(["img1.jpg", "img2.jpg", "img3.jpg"])
```

### Flexible Image Input

```python
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 |

```python
# 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

```python
model = anycv.load_model("yolov8n")
results1 = model(["img1.jpg", "img2.jpg"])
results2 = model("img3.jpg")
```

### Custom Thresholds

```python
detections = anycv.detect("photo.jpg", conf_threshold=0.5, iou_threshold=0.6)
```

### Drawing Results

```python
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.

```bash
# Pre-download all models for offline use
python -m anycv download

# Download only detection models
python -m anycv download --task detection
```

```python
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

```bash
git clone https://github.com/vietanhdev/anycv.git
cd anycv
pip install -e ".[dev]"
pytest tests/ -v
```

## License

MIT License. See [LICENSE](LICENSE) for details.

## Links

- GitHub: [github.com/vietanhdev/anycv](https://github.com/vietanhdev/anycv)
- NRL.ai: [www.nrl.ai](https://www.nrl.ai)
- Author: [Viet-Anh Nguyen](https://github.com/vietanhdev)
