Skip to main content

Host your deep learning models easily.

Project description

Ventu

Help you host your deep learning models easily.

Features

  • Only need to implement Model(inference, preprocess, postprocess)
  • request & response data check using pydantic
  • API document using SpecTree
  • health check

Example

source code can be found in demo.py

from ventu import VentuModel, VentuService
from typing import Tuple
from pydantic import BaseModel
import numpy
import onnxruntime


# define the input schema
class Input(BaseModel):
    x: Tuple[(str,) * 3]


# define the output schema
class Output(BaseModel):
    label: Tuple[(bool,) * 3]


class CustomModel(VentuModel):
    def __init__(self, *args, **kwargs):
        super().__init__()
        # load model
        self.sess = onnxruntime.InferenceSession('./sigmoid.onnx')
        self.input_name = self.sess.get_inputs()[0].name
        self.output_name = self.sess.get_outputs()[0].name

    def preprocess(self, data: Input):
        # data format is defined in ``Input``
        words = [sent.split(' ')[:4] for sent in data.x]
        # padding
        words = [word + [''] * (4 - len(word)) for word in words]
        # build embedding
        emb = [[
            numpy.random.random(5) if w else [0] * 5
            for w in word]
            for word in words]
        return numpy.array(emb, dtype=numpy.float32)

    def inference(self, data):
        # model inference
        return self.sess.run([self.output_name], {self.input_name: data})[0]

    def postprocess(self, data) -> Output:
        # generate the same format as defined in ``Output``
        return {'label': [bool(numpy.mean(d) > 0.5) for d in data]}


if __name__ == "__main__":
    service = VentuService(CustomModel, Input, Output)
    service.run(host='localhost', port=8000)

Run with Gunicorn

gunicorn -w 2 service.app

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

ventu-0.1.0.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

ventu-0.1.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file ventu-0.1.0.tar.gz.

File metadata

  • Download URL: ventu-0.1.0.tar.gz
  • Upload date:
  • Size: 3.8 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.4

File hashes

Hashes for ventu-0.1.0.tar.gz
Algorithm Hash digest
SHA256 013cd8c5ecacb38b2590af2c843b0b2bcbc16006399ebe85f96150ed14da5ba5
MD5 604e69708d6cbac7abcc95e350cb2ac4
BLAKE2b-256 18c4b68bfc757f2b62f8a8df4f44529a63406e2c7bda250ba7f34bc9d5513f2d

See more details on using hashes here.

File details

Details for the file ventu-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ventu-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: 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.4

File hashes

Hashes for ventu-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 695b8fe4d3eb4c1a4befd535329ae20e89ecd58e34778b69fc97070d642a0d81
MD5 59583fc475a05387bd5bd85f372a665e
BLAKE2b-256 db2a4a9ece4c3dbed02950abd17275b9e5fd46b91a3623c1ff8db07b7f055df4

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