Skip to main content

mas-lwym 🚀

mas-lwym is an ultra-lightweight, high-accuracy, single-class (person) object detection library designed for extreme cost efficiency and high throughput on commodity CPUs, edge devices, and GPUs.

Built from the ground up for production deployment, mas-lwym runs exclusively on ONNX Runtime with pure NumPy/OpenCV pre/post-processing, zero runtime framework bloat, seamless CPU/GPU hardware toggles, and 100% Apache-2.0 commercial compliance.


🌟 Key Features

  • ⚡ Ultra-Lightweight & Fast: Sub-5ms latency and 150–250+ FPS on standard CPUs.
  • 🎯 Single-Class Person Focus: Eliminates multi-class softmax/NMS overhead for maximum efficiency.
  • 💻 Pure ONNX Runtime Core: No heavy PyTorch or PaddlePaddle dependencies needed during inference.
  • 🔄 Seamless Hardware Toggle: Switch between device="cpu" and device="gpu" with automatic graceful fallback.
  • 🛠️ Integrated Converter: Built-in convert_to_onnx() utility to convert checkpoints (.pdparams, .pdmodel) to standalone, graph-optimized ONNX models.
  • 📊 Profiling & Diagnostics: Built-in latency (P50/P95/P99), FPS, and hardware execution provider benchmark suite.
  • ⚖️ Commercial Friendly: Free from copyleft/AGPL constraints (Apache-2.0).

📦 Installation

# Using uv (recommended)
uv add mas-lwym

# Or using pip
pip install mas-lwym

🚀 Quickstart

1. Python API

import cv2
from mas_lwym import PersonDetector

# Initialize detector (CPU by default, or device="gpu" / "cuda" / "directml")
detector = PersonDetector(
    model_path="models/picodet_s_320_pedestrian.onnx",
    device="cpu",               # "cpu" | "gpu" | "cuda" | "directml"
    confidence_threshold=0.40,
    iou_threshold=0.45,
    input_shape=(320, 320),
)

# 1. Run inference on an image
image = cv2.imread("street.jpg")
result = detector.predict(image)

print(f"Persons detected: {result.count}")
print(f"Total time: {result.total_time_ms:.2f} ms ({result.fps:.1f} FPS)")

for box in result.boxes:
    print(f"Confidence: {box.score:.2f} | Coordinates: {box.xyxy}")

# 2. Render bounding boxes and HUD
annotated_frame = detector.render(image, result, show_fps=True)
cv2.imwrite("output.jpg", annotated_frame)

2. Real-Time Webcam / Video Stream

from mas_lwym import PersonDetector, VideoPipeline

detector = PersonDetector(model_path="models/picodet_s_320_pedestrian.onnx", device="cpu")
pipeline = VideoPipeline(detector)

# Stream from webcam (0) or video file ("video.mp4")
pipeline.process_stream(source=0, show=True)

3. Model Conversion (convert_to_onnx)

from mas_lwym import convert_to_onnx

# Convert Paddle / PicoDet checkpoint to optimized standalone ONNX
convert_to_onnx(
    model_path="models/picodet_s_320_pedestrian",
    output_path="models/picodet_s_320_pedestrian.onnx",
    input_shape=(320, 320),
    simplify=True,
)

🖥️ Command-Line Interface (CLI)

Check Hardware & Available Execution Providers

mas-lwym devices

Benchmark Model Latency & FPS

mas-lwym benchmark --model models/picodet_s_320_pedestrian.onnx --device cpu --iterations 100

Run Detection via CLI

mas-lwym detect --model models/picodet_s_320_pedestrian.onnx --source frame.jpg --device cpu --save output.jpg

Convert Checkpoints to ONNX

mas-lwym convert --input models/picodet_s_320_pedestrian --output models/picodet_s_320_pedestrian.onnx --shape 320

📂 Package Architecture

src/mas_lwym/
├── core/             # Typed dataclasses (BoundingBox, DetectionResult, DeviceType)
├── engine/           # ONNX Runtime session & hardware provider management
├── processing/       # Vectorized letterbox preprocessor, single-class NMS, visualizer
├── converter/        # Checkpoint to ONNX export router & graph optimizer
├── pipeline/         # High-level PersonDetector and VideoPipeline streams
├── benchmark/        # Latency percentiles (P50/P95/P99) & throughput profiler
└── cli/              # Unified command line tool (mas-lwym)

📄 License

This project is licensed under the Apache License 2.0 - free for both commercial and personal use.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mas_lwym-0.1.0.tar.gz (16.4 kB view details)

Uploaded Source

Built Distribution

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

mas_lwym-0.1.0-py3-none-any.whl (26.2 kB view details)

Uploaded Python 3

File details

Details for the file mas_lwym-0.1.0.tar.gz.

File metadata

  • Download URL: mas_lwym-0.1.0.tar.gz
  • Upload date:
  • Size: 16.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for mas_lwym-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fe8d8fff1d60cb1e712a36afd39d8c45af863aac8b62780787aece07ca59b0e7
MD5 73b8c3b8c3d4034eef70b31cff760aec
BLAKE2b-256 44d8a12da2e452a69cd0926dfdab17f068e872bee3b0653ea266d80d547c35b2

See more details on using hashes here.

File details

Details for the file mas_lwym-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mas_lwym-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 26.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for mas_lwym-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cc4f37cf75e210f410891e949a2de4ed21b3148224b2afac9802e642b1a01f51
MD5 03aff350e8aa3e0a44c3f0ef778ba7c4
BLAKE2b-256 2351b58ee08e81b9ec1fcfbde889f0f997928a2625b28a26573842d36f573060

See more details on using hashes here.

Release history Release notifications | RSS feed

0.2.3

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.8

2 files

0.1.7

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

This release

0.1.0 This release

2 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