Example #1
0
 def __init__(self, name, predictor_host):
     super().__init__(name)
     self.predictor_host = predictor_host
     self.preprocessor = create_preprocessor('xception', target_size=(299, 299))
     self.labels = [
         'dress',
         'hat',
         'longsleeve',
         'outwear',
         'pants',
         'shirt',
         'shoes',
         'shorts',
         'skirt',
         't-shirt'
     ]
Example #2
0
def main():
    parser = configure_arg_parser()
    args, _ = parser.parse_known_args()

    size = os.environ['MODEL_INPUT_SIZE']
    size_h, size_w = size.split(',')
    size_h = int(size_h)
    size_w = int(size_w)

    keras_model = os.environ['KERAS_MODEL_NAME']
    labels = os.environ['MODEL_LABELS'].split(',')

    preprocessor = create_preprocessor(keras_model,
                                       target_size=(size_w, size_w))

    transformer = ImageTransformer(args.model_name,
                                   predictor_host=args.predictor_host,
                                   preprocessor=preprocessor,
                                   labels=labels)

    kfserver = kfserving.KFServer()
    kfserver.start(models=[transformer])
Example #3
0
import grpc
import os
import tensorflow as tf
from tensorflow_serving.apis import predict_pb2
from tensorflow_serving.apis import prediction_service_pb2_grpc

from keras_image_helper import create_preprocessor
from flask import Flask, request, jsonify

host = os.getenv('TF_SERVING_HOST', 'localhost:8500')
channel = grpc.insecure_channel(host)

stub = prediction_service_pb2_grpc.PredictionServiceStub(channel)
preprocessor = create_preprocessor('xception', target_size=(299, 299))
labels = [
    'dress', 'hat', 'longsleeve', 'outwear', 'pants', 'shirt', 'shoes',
    'shorts', 'skirt', 't-shirt'
]


def np_to_protobuf(data):
    return tf.make_tensor_proto(data, shape=data.shape)


def make_request(X):
    pb_request = predict_pb2.PredictRequest()
    pb_request.model_spec.name = 'clothing-model'
    pb_request.model_spec.signature_name = 'serving_default'
    pb_request.inputs['input_8'].CopyFrom(np_to_protobuf(X))
    return pb_request
Example #4
0
def lambda_handler(event, context):
    url = event['url']
    preprocessor = create_preprocessor('xception', target_size=(150, 150))
    x = preprocessor.from_url(url)
    pred = predict(x)
    return {"result": pred}