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.2.tar.gz (16.7 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.2-py3-none-any.whl (26.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mas_lwym-0.1.2.tar.gz
  • Upload date:
  • Size: 16.7 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.2.tar.gz
Algorithm Hash digest
SHA256 7fd2b869236b2eddb50f9d786395b57abd95823fe004c41870fd4515eee26d65
MD5 783cbb1c8716c10abfca1c880420688b
BLAKE2b-256 adab8d51c03386324587c7e90461025ed2755e45c2ca618b095534924c1eb5c4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mas_lwym-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 26.4 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 dd8299bebd083297f4cf40d39716d916f8d6bf979cbd3ca358b1d368fc9870e4
MD5 565ac77938c67748ee7fa992a481bb29
BLAKE2b-256 1bb45b3084b72f0ddd0243d20823b8d9f4285ec635cb370c09c1f808bd7b1eb8

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

This release

0.1.2 This release

2 files

0.1.1

2 files

0.1.0

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