A utility library for Stonecrest Data Solution's Martensite ONNX Inference Server
Project description
Martensite Utils
Welcome to Martensite Utils! This Python package is developed by Stonecrest Data Solutions and is designed to be used in conjunction with our Martensite Docker Container. It is a simple package that is designed to handle the transmission of Numpy Arrays over TCP by serializing the Arrays into a Protobuf Message. Since a lot of this is complex and usually outside the normal realm of AI/ML Engineers, we developed Martensite Utils to simplify this process.
Though Martensite Utils was designed to be used with Martensite, we can see the potential benefit of using it in other projects that need to send Numpy Arrays over TCP and would encourage this type of usage.
Usage
There are a handful of translations that are included in Martensite Utils:
- Numpy Array -> Protobuf Message (
numpy_to_proto()) - Numpy Array -> Serialized Protobuf Message (
numpy_to_raw_proto()) - Protobuf Message -> Numpy Array (
proto_to_numpy()) - Serialized Protobuf Message -> Numpy Array (
raw_proto_to_numpy())
The typical process that is used for sending a Numpy Array to an endpoint is:
- Create Numpy Array
- Translate Numpy Array to Protobuf Message
- Serialize Protobuf Message
- Attach serialized Protobuf Message to request data
- Send request
And to receive a Numpy Array:
- Receive Request
- Deserialize request data as Protobuf Message
- Translate Protobuf Message into Numpy Array
Note: For both sending and receiving, steps 2&3 can be replaced by their corresponding "raw" calls.
Example
This example code creates a random Numpy Array, translates it to a serialized Protobuf Message, sends it to the inference endpoint of a locally hosted Martensite server, then parses the received data into a Numpy Array.
import numpy as np
import requests
from martensite_utils import numpy_to_raw_proto
from martensite_utils import raw_proto_to_numpy
input_array = np.random.random((10, 10))
input_data = numpy_to_raw_proto(input_array)
response = requests.post(
url="http://127.0.0.1:8000/inference",
data=input_data
)
received_data = raw_proto_to_numpy(response.content)
print(f"Result: {received_data}")
There is also a helper function at martensite_utils.post_numpy_array() that
takes care of the translation and transmission all at once. View its docstring
to learn how to use it.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file martensite_utils-0.0.2.tar.gz.
File metadata
- Download URL: martensite_utils-0.0.2.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a0728f7feef538e36065fc37a212686dc3e8a20813eabb9f64e92290ee6f8d13
|
|
| MD5 |
25b1bb43f651f9fdc3ab9b4d7ebadf23
|
|
| BLAKE2b-256 |
d64660784c1b4024f63238fee2d110eef30c13ea5c50fe76d43139e8b1929382
|
File details
Details for the file martensite_utils-0.0.2-py3-none-any.whl.
File metadata
- Download URL: martensite_utils-0.0.2-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
49642e6bf5e314f1b235a74f25d586f3cf1101b3787f9aaadde0c240be213de8
|
|
| MD5 |
cb2de148182df0b5f27f893b2244ac6d
|
|
| BLAKE2b-256 |
47b776c0d3f9886c1c525148860d85baeb430846fef25e1ecf8278b60a5c2506
|