Coder Social home page Coder Social logo

parrondo / deeptrading-tfserving-python Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 3.0 70.34 MB

Tensorflow serving client implementation for trading.

Home Page: https://todotrader.com/deep-trading-with-tensorflow-viii/

Python 98.86% Shell 1.14%
trading trading-algorithms trading-systems machine-learning machinelearning-python forex-prediction forex-trading

deeptrading-tfserving-python's Introduction

deeptrading-tfserving-python

Tensorflow serving client

This is a tensorflow serving client implementation from https://github.com/epigramai/tfserving-python-predict-client.

You can find here a Tensorflow client examples to trade.

The predict client is meant to be used with a model served by TensorFlow Serving. Because tfserving model server runs a gRPC service, it cannot be requested by just sending a normal HTTP request. The predict_client package is a grcp client that can request the service.

Read the author's blog posts about TensorFlow Serving:

Part 1 and Part 2

and also my post serie: Deeptrading with tensorflow specially: https://todotrader.com/deep-trading-with-tensorflow-viii/

Install

conda create --name myenv

$ conda activate myenv

(myenv)$ pip install git+https://github.com/parrondo/deeptrading-tfserving-python.git

If you need a model server

There is one here https://github.com/bitnami/bitnami-docker-tensorflow-serving

How to use

Check out the examples.

Example 1 use fixed enter data and request a response from the serving model.

Example 2 generates random data simulating some Forex enter data and request a response from the serving model.

predict_client.prod_client ProdClient

def init(self, host, model_name, model_version):

  • host: the host (e.g. '0.0.0.0:8500')
  • model_name: your model name, e.g. '07_First_Forex_Prediction'
  • model_version: model version, e.g. 1.

ProdClient.predict(self, request_data, request_timeout=10):

  • request_data: A list of input tensors, see the example.
  • request_timeout: timeout sent to the grcp stub

from predict_client.prod_client import ProdClient

client = ProdClient('localhost:9000', 'mnist', 1)

client.predict(request_data)

The predict function returns a dictionary with keys and values for each output tensor. The values in the dictionary will have the same shapes as the output tensor's shape. If an error occurs, predict will return an empty dict.

predict_client.inmemory_client InMemoryClient

def init(self, model_path):

  • model_path

InMemoryClient.predict(self, request_data, request_timeout=None):

  • request_data and request_timeout same as ProdClient, except request_timeout not used in this client.

from predict_client.inmemory_client import InMemoryClient

client = InMemoryClient('path/to/model.pb')

client.predict(request_data)

The predict function returns a dictionary with keys and values for each output tensor. The values in the dictionary will have the same shapes as the output tensor's shape. If an error occurs, predict will return an empty dict.

predict_client.mock_client MockClient

def init(self, mock_response):

  • mock_response

MockClient.predict(self, request_data, request_timeout=None):

  • request_data and request_timeout same as ProdClient, except request_timeout not used in mock client.

from predict_client.mock_client import MockClient

client = MockClient(mock_response)

client.predict(request_data)

The mock client predict function simply returns the mock response.

Development

Generate python code from .proto files

Caution, this is not always trivial!

pip install grpcio-tools python -m grpc_tools.protoc -I protos/ --python_out=predict_client/pbs --grpc_python_out=predict_client/pbs protos/*

deeptrading-tfserving-python's People

Contributors

parrondo avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.