A Python package for running Spottyr workflow on edge devices.
Project description
Spottyr Edge Runtime
A Python library for running Spottyr AI workflows on edge devices. This runtime allows you to package, deploy, and execute machine learning workflows with ONNX models in a standardized way.
Features
- Workflow Packaging: Load and execute workflows from ZIP files or directories
- ONNX Model Support: Automatic loading and management of ONNX models
- Structured Output: JSON-based result handling with error management
- Edge Device Optimized: Lightweight runtime suitable for edge deployment
- Flexible Configuration: JSON-based workflow configuration with
signature.json
Installation
From PyPI
pip install spottyr-edge-runtime
Dependencies
The package requires Python 3.8+ and the following dependencies:
- Pillow >= 9.0.0
- numpy >= 1.22.0
- opencv-python >= 4.8.0.74
- onnxruntime >= 1.12.0
Quick Start
Basic Usage
from spottyr_edge_runtime.workflow import SpottyrWorkflow
from PIL import Image
# Create workflow instance
workflow = SpottyrWorkflow()
# Load workflow from ZIP file
workflow.load("path/to/workflow.zip")
# Load an image
image = Image.open("path/to/image.jpg")
# Execute the workflow
result = workflow.invoke(image)
# Check results
if result.success:
print(f"Prediction: {result.prediction}")
else:
print(f"Error: {result.error}")
Creating Your Own Workflow
To create a workflow that works with the Spottyr Edge Runtime:
- Create a directory with your workflow files
- Include a
signature.jsonconfiguration file - Create a
main.pyentry point - Add your ONNX model files
- Package as a ZIP file for distribution
Workflow Structure
Directory Layout
A workflow package should have the following structure:
workflow_package/
├── main.py # Entry point script
├── signature.json # Workflow configuration
├── model.onnx # ONNX model file(s)
└── additional_modules.py # Supporting code
signature.json Configuration
The signature.json file defines the workflow configuration:
{
"models": {
"model_name": {
"type": "onnx",
"path": "model.onnx",
"conf_threshold": 0.6,
"iou_threshold": 0.5,
"class_names": ["class1", "class2", "class3"]
}
},
"workflow": {
"name": "Workflow Name",
"version": "1.0.0",
"description": "Workflow description"
},
"classes": {
"Label": ["label1", "label2", "label3"]
}
}
main.py Entry Point
Your workflow's main.py should:
- Accept an image path as a command line argument
- Process the image using the loaded ONNX model
- Output results as JSON to stdout
#!/usr/bin/env python3
import sys
import json
def set_preloaded_model(models, models_config=None):
"""Called by SpottyrWorkflow to provide pre-loaded models"""
global PRELOADED_MODELS
PRELOADED_MODELS = models
def main():
if len(sys.argv) != 2:
print(json.dumps({"error": "Usage: python main.py <image_path>"}))
return
image_path = sys.argv[1]
# Process image with your model
prediction = process_image(image_path)
# Output result as JSON
result = {
"prediction": prediction,
"success": True
}
print(json.dumps(result))
if __name__ == "__main__":
main()
Project details
Release history Release notifications | RSS feed
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 spottyr_edge_runtime-0.1.6.tar.gz.
File metadata
- Download URL: spottyr_edge_runtime-0.1.6.tar.gz
- Upload date:
- Size: 10.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a10a30ec210186a9ae28e639e47cdced1db30ffb3c12e44a4b5950df252384bf
|
|
| MD5 |
39ef8c047ffe7df894db31886cfc1f20
|
|
| BLAKE2b-256 |
4a49ffb1be8f940278ab922fe7b2c1e5be86a804c8eed133cc1eaa4fbe354890
|
File details
Details for the file spottyr_edge_runtime-0.1.6-py3-none-any.whl.
File metadata
- Download URL: spottyr_edge_runtime-0.1.6-py3-none-any.whl
- Upload date:
- Size: 9.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c841f7a8bd9367a0e3299d336781143b55ebe94a6794b24ab9762070d04f587b
|
|
| MD5 |
62882cb66b6ab97dbc8620ee9672dacf
|
|
| BLAKE2b-256 |
969b9bdcb7ad96d506edf26e438c255a83a6b7786695ea87174e76ff56762665
|