Slide 14
Slide 14 text
Implement server and client !14
1 class Servicer(detection_pb2_grpc.MLServerServicer):
2 def __init__(self, predictor):
3 self._predictor = predictor
4
5 def predict(self, request_iterator, context):
6 image = save_chunks_to_file_object(request_iterator)
7 # predict
8 boxes, classes, confs = self._predictor.predict(image)
9 bboxes = [detection_pb2.Boundingbox(box=box) for box in boxes]
10 return detection_pb2.Reply(boxes=bboxes, classes=classes, confs=confs)
1 class MLClient(object):
2 def __init__(self, address, parse=None):
3 channel = grpc.insecure_channel(address)
4 self.stub = detection_pb2_grpc.MLServerStub(channel)
5 self._parse = parse
6
7 def predict(self, in_file):
8 chunks_generator = get_virtual_file_chunks(in_file)
9 response = self.stub.predict(chunks_generator)
10 if self._parse != None:
11 response = self._parse(response)
12 return response
Client Code
Service Code