Skip to main content

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

Metadata

Release files for m3da 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for m3da 0.1.2
File Size Uploaded
m3da-0.1.2.tar.gz 4.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for m3da 0.1.2
File Interpreter ABI Platform
m3da-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 8.3 kB

Release files / m3da-0.1.2.tar.gz

Download URL m3da-0.1.2.tar.gz
Size 4.1 kB
Tags Source
SHA-256 checksum
How to use checksums
afc5f5f5fef774abcefb474fd94fe3fac00576975fbbaec9a6638e034d599e8b
BLAKE2b-256 checksum
How to use checksums
b72ff10e5fd02437cf44a4463a68dce07ab46e763ccb06d98eaea9d23abadfce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Release files / m3da-0.1.2-py3-none-any.whl

Download URL m3da-0.1.2-py3-none-any.whl
Size 4.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
92032072730f057d47b4d0f90b5770ed4a408fd35b3ef552ebddd41034490a88
BLAKE2b-256 checksum
How to use checksums
9e207e99446b85fff74b7ea0223955a088d97822f14d319e43ad0f3679426a6c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release 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