def test_proto_bin_data(): user_object = UserObject() app = SeldonModelGRPC(user_object) bdata = b"123" bdata_base64 = base64.b64encode(bdata) request = prediction_pb2.SeldonMessage(binData=bdata_base64) resp = app.Predict(request, None) assert resp.binData == bdata_base64
def test_proto_bin_data_nparray(): user_object = UserObject(ret_nparray=True) app = SeldonModelGRPC(user_object) binData = b"\0\1" request = prediction_pb2.SeldonMessage(binData=binData) resp = app.Predict(request, None) jStr = json_format.MessageToJson(resp) j = json.loads(jStr) print(j) assert j["data"]["tensor"]["values"] == list(user_object.nparray.flatten())
def test_proto_feedback_custom(): user_object = UserObjectLowLevel() app = SeldonModelGRPC(user_object) arr = np.array([1, 2]) datadef = prediction_pb2.DefaultData( tensor=prediction_pb2.Tensor( shape=(2, 1), values=arr ) ) request = prediction_pb2.SeldonMessage(data=datadef) feedback = prediction_pb2.Feedback(request=request,reward=1.0) resp = app.SendFeedback(feedback, None)
def test_proto_lowlevel(): user_object = UserObjectLowLevel() app = SeldonModelGRPC(user_object) arr = np.array([1, 2]) datadef = prediction_pb2.DefaultData( tensor=prediction_pb2.Tensor( shape=(2, 1), values=arr ) ) request = prediction_pb2.SeldonMessage(data=datadef) resp = app.Predict(request, None) jStr = json_format.MessageToJson(resp) j = json.loads(jStr) print(j) assert j["data"]["tensor"]["shape"] == [2, 1] assert j["data"]["tensor"]["values"] == [9, 9]
def test_proto_tftensor_ok(): user_object = UserObject() app = SeldonModelGRPC(user_object) arr = np.array([1, 2]) datadef = prediction_pb2.DefaultData( tftensor=tf.make_tensor_proto(arr) ) request = prediction_pb2.SeldonMessage(data=datadef) resp = app.Predict(request, None) jStr = json_format.MessageToJson(resp) j = json.loads(jStr) print(j) assert j["meta"]["tags"] == {"mytag": 1} # add default type j["meta"]["metrics"][0]["type"] = "COUNTER" assert j["meta"]["metrics"] == user_object.metrics() arr2 = tf.make_ndarray(resp.data.tftensor) assert np.array_equal(arr, arr2)
def test_proto_ok(): user_object = UserObject() app = SeldonModelGRPC(user_object) arr = np.array([1, 2]) datadef = prediction_pb2.DefaultData( tensor=prediction_pb2.Tensor( shape=(2, 1), values=arr ) ) request = prediction_pb2.SeldonMessage(data=datadef) resp = app.Predict(request, None) jStr = json_format.MessageToJson(resp) j = json.loads(jStr) print(j) assert j["meta"]["tags"] == {"mytag": 1} # add default type j["meta"]["metrics"][0]["type"] = "COUNTER" assert j["meta"]["metrics"] == user_object.metrics() assert j["data"]["tensor"]["shape"] == [2, 1] assert j["data"]["tensor"]["values"] == [1, 2]
def test_proto_gets_meta(): user_object = UserObject(ret_meta=True) app = SeldonModelGRPC(user_object) arr = np.array([1, 2]) datadef = prediction_pb2.DefaultData( tensor=prediction_pb2.Tensor( shape=(2, 1), values=arr ) ) meta = prediction_pb2.Meta() metaJson = {"puid":"abc"} json_format.ParseDict(metaJson, meta) request = prediction_pb2.SeldonMessage(data=datadef, meta=meta) resp = app.Predict(request, None) jStr = json_format.MessageToJson(resp) j = json.loads(jStr) print(j) assert j["meta"]["tags"] == {"inc_meta":{"puid":"abc"}} # add default type j["meta"]["metrics"][0]["type"] = "COUNTER" assert j["meta"]["metrics"] == user_object.metrics() assert j["data"]["tensor"]["shape"] == [2, 1] assert j["data"]["tensor"]["values"] == [1, 2]