Skip to main content

A lightweight package for image classification using ONNX models

Project description

M3da

A lightweight Python package for image classification using ONNX models.

Installation

pip install m3da

Features

  • Simple interface for image classification using ONNX models
  • Automatic image preprocessing and normalization
  • Input validation to prevent common errors
  • Compatible with any ONNX model trained for image classification

Requirements

  • Python 3.7+
  • onnxruntime
  • numpy
  • Pillow (PIL)

Quick Start

import m3da

# Classify an image
result = m3da.execute(
    modelPath="path/to/your/model.onnx",
    pathToImage="path/to/your/image.jpg",
    classNames=["class1", "class2", "class3"],
    imgDimensions=(224, 224)
)

print(f"Predicted class: {result['class']}")
print(f"Confidence: {result['confidence']:.2f}")
print(f"Class index: {result['class_index']}")

Parameters

The execute() function accepts the following parameters:

  • modelPath (str): Path to the ONNX model file (must have .onnx extension)
  • pathToImage (str): Path to the image file to classify
  • classNames (list): List of class names corresponding to the model's output indices
  • imgDimensions (tuple): Tuple of (width, height) for image resizing

Return Value

The function returns a dictionary with the following keys:

  • class (str): The predicted class name
  • confidence (float): The confidence score for the prediction
  • class_index (int): The index of the predicted class

Example

Classifying an image of a pet using a pre-trained model:

import m3da

classes = ["cat", "dog", "hamster", "rabbit", "goldfish"]

result = m3da.execute(
    modelPath="pet_classifier.onnx",
    pathToImage="my_pet.jpg",
    classNames=classes,
    imgDimensions=(32, 32)
)

print(f"This image appears to be a {result['class']} with {result['confidence']:.1%} confidence.")

License

MIT

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

m3da-0.1.0.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

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

m3da-0.1.0-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: m3da-0.1.0.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for m3da-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8bc2dc350037ea71fe06ef66a714f76266b8c0b73809b0843432664f5acc5b99
MD5 5b380ecf7b44376f63070c0ef93d6541
BLAKE2b-256 9c5af111a9b2df14e7da7a134c926f090ff089983e5e9ed78cec1964ef02b58d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: m3da-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for m3da-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ff4c2e38e4aa99cf77070f73dbed2e132681f1e31640bc1f7373688ae7db2edd
MD5 7787341c10fa44efb29ec5172644deb1
BLAKE2b-256 d6a3fc3bf56c7fce9cae445c570695aba71c4e2c92b7c95a56e952b429cea9c7

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