d0995b37 by Lyu Kui

modify locustfile

1 parent a33165ce
......@@ -28,7 +28,7 @@ class F3Classification:
res = {
'label': label,
'confidence': confidence
'confidence': float(confidence)
}
return res
......
......@@ -14,3 +14,10 @@ class QuickstartUser(HttpUser):
@task
def async_test(self):
self.client.get("/async")
@tag('sync_classification')
@task
def sync_classification(self):
img_path = '/home/lk/MyProject/BMW_F3OCR/数据集/文件分类/营业执照/授信资料-43.jpg'
files=[('image', ('', open(img_path,'rb'), ''))]
self.client.post("/sync_classification", files=files)
......
import grpc
import os
import cv2
import grpc
import numpy as np
import tensorflow as tf
from tensorflow_serving.apis import prediction_service_pb2_grpc, predict_pb2
......@@ -8,6 +9,7 @@ from sanic import Sanic
from sanic.response import json
from classification import classifier
os.environ['CUDA_VISIBLE_DEVICES'] = '-1'
app = Sanic("async_test")
......@@ -15,7 +17,7 @@ app = Sanic("async_test")
tf_serving_settings = {
'servers': {
'server_1': {
'host': '192.168.10.191',
'host': 'localhost',
'port': '8500',
'options': [
('grpc.max_send_message_length', 1000 * 1024 * 1024),
......@@ -40,7 +42,7 @@ async def sync_handler(request):
request = predict_pb2.PredictRequest()
request.model_spec.name = classifier.model_name
request.model_spec.signature_name = classifier.signature_name
stub = getattr(app.ctx, classifier.server_name)
stub = getattr(app, classifier.server_name)
request.inputs['input_1'].CopyFrom(tf.make_tensor_proto(input_images))
result = stub.Predict(request, 100.0) # 100 secs timeout
......@@ -63,7 +65,7 @@ async def set_grpc_channel(app, loop):
'{0}:{1}'.format(server_settings['host'], server_settings['port']),
options=server_settings.get('options'))
stub = prediction_service_pb2_grpc.PredictionServiceStub(channel)
setattr(app.ctx, server_name, stub)
setattr(app, server_name, stub)
if __name__ == '__main__':
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!