Skip to main content

Machine learning utilities for model conversion, serialization, loading etc

Project description

Machine learning utilities for model conversion, serialization, loading etc

  • Free software: Apache Software License 2.0

Installation

pip install ml2rt

Documentation

ml2rt provides some convenient functions to convert, save & load machine learning models. It currently supports Tensorflow, PyTorch, Sklearn, Spark and ONNX but frameworks like xgboost, coreml are on the way.

Saving Tensorflow model

import tensorflow as tf
from ml2rt import save_tensorflow
# train your model here
sess = tf.Session()
save_tensorflow(sess, path, output=['output'])

Saving PyTorch model

# it has to be a torchscript graph made by tracing / scripting
from ml2rt import save_torch
save_torch(torch_script_graph, path)

Saving ONNX model

from ml2rt import save_onnx
save_onnx(onnx_model, path)

Saving sklearn model

from ml2rt import save_sklearn
prototype = np.array(some_shape, dtype=some_dtype)  # Equivalent to the input of the model
save_sklearn(sklearn_model, path, prototype=prototype)

# or

# some_shape has to be a tuple and some_dtype has to be a np.dtype, np.dtype.type or str object
save_sklearn(sklearn_model, path, shape=some_shape, dtype=some_dtype)

# or

# some_shape has to be a tuple and some_dtype has to be a np.dtype, np.dtype.type or str object
inital_types = utils.guess_onnx_tensortype(shape=shape, dtype=dtype)
save_sklearn(sklearn_model, path, initial_types=initial_types)

Saving sparkml model

from ml2rt import save_sparkml
prototype = np.array(some_shape, dtype=some_dtype)  # Equivalent to the input of the model
save_sparkml(spark_model, path, prototype=prototype)

# or

# some_shape has to be a tuple and some_dtype has to be a np.dtype, np.dtype.type or str object
save_sparkml(spark_model, path, shape=some_shape, dtype=some_dtype)

# or

# some_shape has to be a tuple and some_dtype has to be a np.dtype, np.dtype.type or str object
inital_types = utils.guess_onnx_tensortype(shape=shape, dtype=dtype)
save_sparkml(spark_model, path, initial_types=initial_types)

Sklearn and sparkml models will be converted to ONNX first and then save to the disk. These models can be executed using ONNXRuntime, RedisAI etc. ONNX conversion needs to know the type of the input nodes and hence we have to pass shape & dtype or a prototype from where the utility can infer the shape & dtype or an initial_type object which is understood by the conversion utility. Frameworks like sparkml allows users to have heterogeneous inputs with more than one type. In such cases, use guess_onnx_tensortypes and create more than one initial_types which can be passed to save function as a list

Loading model & script

Loading function can load both single file models like freezed tensorflow model or torchscript model or onnx model as well as SavedModel from tensorflow

model = ml2rt.load_model(path)

script = ml2rt.load_script(script)

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

ml2rt-0.1.2.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

ml2rt-0.1.2-py2.py3-none-any.whl (7.6 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: ml2rt-0.1.2.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.5

File hashes

Hashes for ml2rt-0.1.2.tar.gz
Algorithm Hash digest
SHA256 2e0269df2822b7acb3d3900dc0cff3307c060c9503787c33ac7fb3fe0389fa1a
MD5 62b31acdcafa7fd3f8689c019810df69
BLAKE2b-256 3e32c7b86ea2487d7ed6494fa6c94f240f77d8460a75135d67e4de87b9d99f3b

See more details on using hashes here.

File details

Details for the file ml2rt-0.1.2-py2.py3-none-any.whl.

File metadata

  • Download URL: ml2rt-0.1.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.5

File hashes

Hashes for ml2rt-0.1.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d783d9912e6ced4746686e9bd0097d13c818e08df70e069c2a4c3f8d9040231d
MD5 4f323e7ede98f74fe09bb21023992327
BLAKE2b-256 fcab4b1d7fa19565ddb038614f36c0303302871340f823567fce7a8accdf9a87

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page