Skip to main content

Universal Inference Pipeline Framework for Computer Vision

Project description

Inferflow

Universal Inference Pipeline Framework

PyPI version Python License Documentation


Overview

InferFlow is a production-grade inference pipeline framework designed for computer vision models. It provides a clean abstraction layer that separates model runtime, preprocessing, postprocessing, and batching strategies, enabling seamless deployment across multiple inference backends.

Key Features:

  • Runtime Agnostic: Support for TorchScript, ONNX, TensorRT, and more (in the future :D)
  • Dynamic Batching: Automatic request batching with adaptive batch sizing
  • Type Safe: Full type hints with generic pipeline definitions
  • Async First: Built on asyncio for high concurrency
  • Production Ready: Comprehensive logging, metrics, and error handling

Installation

pip install inferflow

Development installation:

git clone https://github.com/6ixGODD/inferflow.git
cd inferflow
pip install -e ".[dev]"

Quick Start

Basic Classification

import asyncio
from inferflow.runtime.torch import TorchScriptRuntime
from inferflow.pipeline.classification import ClassificationPipeline

async def main():
    # Setup runtime
    runtime = TorchScriptRuntime(
        model_path="resnet50.pt",
        device="cuda:0",
    )

    # Create pipeline
    pipeline = ClassificationPipeline(
        runtime=runtime,
        class_names={0: "cat", 1: "dog", 2: "bird"},
    )

    # Run inference
    async with pipeline.serve():
        with open("image.jpg", "rb") as f:
            result = await pipeline(f.read())

        print(f"{result.class_name}: {result.confidence:.2%}")

asyncio.run(main())

Object Detection

from inferflow.pipeline.detection import YOLOv5DetectionPipeline

pipeline = YOLOv5DetectionPipeline(
    runtime=runtime,
    conf_threshold=0.5,
    class_names={0: "person", 1: "car"},
)

async with pipeline.serve():
    detections = await pipeline(image_bytes)
    for det in detections:
        print(f"{det.class_name}: {det.confidence:.2%} at {det.box}")

Instance Segmentation

from inferflow.pipeline.segmentation import YOLOv5SegmentationPipeline

pipeline = YOLOv5SegmentationPipeline(
    runtime=runtime,
    conf_threshold=0.5,
    class_names={0: "person"},
)

async with pipeline.serve():
    segments = await pipeline(image_bytes)
    for seg in segments:
        print(f"Mask shape: {seg.mask.shape}, Box: {seg.box}")

Dynamic Batching

Enable automatic request batching for higher throughput:

import asyncio

from inferflow.batch.dynamic import DynamicBatchStrategy
from inferflow.pipeline.classification import ClassificationPipeline

batch_strategy = DynamicBatchStrategy(
    min_batch_size=1,
    max_batch_size=32,
    max_wait_ms=50,
)

pipeline = ClassificationPipeline(
    runtime=runtime,
    batch_strategy=batch_strategy,
)

async with pipeline.serve():
    # Submit concurrent requests - automatically batched
    results = await asyncio.gather(*[
        pipeline(img) for img in images
    ])

Batch metrics:

metrics = batch_strategy.get_metrics()
print(f"Avg batch size: {metrics.avg_batch_size:.2f}")
print(f"Throughput: {metrics.total_requests / elapsed:.2f} req/s")

Architecture

Core Abstractions

graph TB
    subgraph Pipeline["Pipeline"]
        direction LR
        Pre[Preprocess]
        Runtime[Runtime]
        Post[Postprocess]

        Pre -->|Tensor| Runtime
        Runtime -->|Output| Post
    end

    BatchStrategy[BatchStrategy]

    Pre -.->|Batching| BatchStrategy
    Runtime -.->|Batching| BatchStrategy
    Post -.->|Batching| BatchStrategy

    style Pipeline fill:#1a1a1a,stroke:#00d9ff,stroke-width:3px
    style Pre fill:#0d47a1,stroke:#42a5f5,stroke-width:2px,color:#fff
    style Runtime fill:#e65100,stroke:#ff9800,stroke-width:2px,color:#fff
    style Post fill:#6a1b9a,stroke:#ba68c8,stroke-width:2px,color:#fff
    style BatchStrategy fill:#1b5e20,stroke:#66bb6a,stroke-width:2px,color:#fff

Components:

  • Runtime: Model loading and inference execution
  • Pipeline: End-to-end data transformation
  • BatchStrategy: Request aggregation and dispatching

Requirements

  • Python ≥ 3.10
  • PyTorch ≥ 2.1
  • OpenCV ≥ 4.5

Contributing

Contributions are not currently accepted. This project is maintained for internal use.


License

MIT License. See LICENSE for details.


Citation

@software{inferflow2025,
  title={InferFlow: Universal Inference Pipeline Framework},
  author={6ixGODD},
  year={2025},
  url={https://github.com/6ixGODD/inferflow}
}

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

inferflow-0.1.0a2.tar.gz (24.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

inferflow-0.1.0a2-py3-none-any.whl (34.5 kB view details)

Uploaded Python 3

File details

Details for the file inferflow-0.1.0a2.tar.gz.

File metadata

  • Download URL: inferflow-0.1.0a2.tar.gz
  • Upload date:
  • Size: 24.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for inferflow-0.1.0a2.tar.gz
Algorithm Hash digest
SHA256 fc550976f5dc16db94713547c313398b16ef6b7c94fb54c88c8a70a3062ad5be
MD5 5c8f78df1bf45365e523b51796e45cd2
BLAKE2b-256 3ba68715b266c0ffcdfb2f90fdc67185d389a51b244963af8fecb7336b133c2b

See more details on using hashes here.

Provenance

The following attestation bundles were made for inferflow-0.1.0a2.tar.gz:

Publisher: publish.yml on 6ixGODD/inferflow

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file inferflow-0.1.0a2-py3-none-any.whl.

File metadata

  • Download URL: inferflow-0.1.0a2-py3-none-any.whl
  • Upload date:
  • Size: 34.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for inferflow-0.1.0a2-py3-none-any.whl
Algorithm Hash digest
SHA256 fd4ca174f7c20814135e7f5c911518082c50b4f5a294c27e08d59c25c91180d0
MD5 da307f6ff03085eeaa72ce7b688f9a12
BLAKE2b-256 4b468d128a981e9ca1969d676a2ac0558135e53a7e2992d02818b7fbc87c5126

See more details on using hashes here.

Provenance

The following attestation bundles were made for inferflow-0.1.0a2-py3-none-any.whl:

Publisher: publish.yml on 6ixGODD/inferflow

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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