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.2.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.2-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: m3da-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 afc5f5f5fef774abcefb474fd94fe3fac00576975fbbaec9a6638e034d599e8b
MD5 9c82a9d616fb0635a0a12537cc3a81a2
BLAKE2b-256 b72ff10e5fd02437cf44a4463a68dce07ab46e763ccb06d98eaea9d23abadfce

See more details on using hashes here.

File details

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

File metadata

  • Download URL: m3da-0.1.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 92032072730f057d47b4d0f90b5770ed4a408fd35b3ef552ebddd41034490a88
MD5 647ad740b90898f561f41aec2be43d08
BLAKE2b-256 9e207e99446b85fff74b7ea0223955a088d97822f14d319e43ad0f3679426a6c

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