Skip to main content

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:

  1. Create a directory with your workflow files
  2. Include a signature.json configuration file
  3. Create a main.py entry point
  4. Add your ONNX model files
  5. 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:

  1. Accept an image path as a command line argument
  2. Process the image using the loaded ONNX model
  3. 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


Download files

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

Source Distribution

spottyr_edge_runtime-0.1.5.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

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

spottyr_edge_runtime-0.1.5-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file spottyr_edge_runtime-0.1.5.tar.gz.

File metadata

  • Download URL: spottyr_edge_runtime-0.1.5.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for spottyr_edge_runtime-0.1.5.tar.gz
Algorithm Hash digest
SHA256 d2abd18c20952c2800a924d3874f2a4aa46715b077ed4433464444d673e2fea4
MD5 f78dfda15b58c5470c2941b99ca4bc64
BLAKE2b-256 4060135c684325eb0756e82bc0b384be8af8c62cbdc98a79a33c2e2657c95220

See more details on using hashes here.

File details

Details for the file spottyr_edge_runtime-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for spottyr_edge_runtime-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 ab80b4f3516bbc9d1415f7cfac9ad0bb8b5c783beb3471e1b309af4693253eaa
MD5 89b331f4620ad3f359a0824b7d4b557e
BLAKE2b-256 822aabae3e8cf723c613a8852f6573bd38347c23a97cdf1ab4a2d567b97c38d5

See more details on using hashes here.

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