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

Uploaded Python 3

File details

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

File metadata

  • Download URL: m3da-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 8aa9360b3e96b323dcfd70cbb65e100f944b42f5582fa9c5dca505ba4f2c33d7
MD5 42b33188500c464fd417339aff47eaf7
BLAKE2b-256 fabe6e0206b8cb84e9299b6b29c2ec1bd154e9689099788c07f868ed112ce159

See more details on using hashes here.

File details

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

File metadata

  • Download URL: m3da-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 22983a3cc38887a1f3ef205da2e60c22d0a8582b133d52ed3dbf207b9f0dc6d4
MD5 208a02f0204d08204888e67cc7d9a427
BLAKE2b-256 cd1a56fdc4a8043cff3aa1da566ab11730da26a747e644f73f0b3cc2e8242143

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