Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to seldon request logging #872

Merged
merged 1 commit into from
Sep 17, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions seldon-request-logger/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ def index():
responseMsg = json_to_seldon_message(responseCopy)
(res_features, _, res_datadef, res_datatype) = extract_request_parts(responseMsg)
res_elements = createElelmentsArray(res_features,list(res_datadef.names))

if not req_elements is None and not res_elements is None:
for i,(a,b) in enumerate(zip(req_elements,res_elements)):
merged = {**a, **b}
content["elements"] = merged
# merged = {**a, **b}
content["request_elements"] = a
content["response_elements"] = b
reqJson = extractRow(i, requestMsg, req_datatype, req_features, req_datadef)
resJson = extractRow(i, responseMsg, res_datatype, res_features, res_datadef)
content["request"] = reqJson
Expand All @@ -49,13 +50,13 @@ def index():
print(str(json.dumps(content)))
elif not req_elements is None:
for i,e in enumerate(req_elements):
content["elements"] = e
content["request_elements"] = e
reqJson = extractRow(i, requestMsg, req_datatype, req_features, req_datadef)
content["request"] = reqJson
print(str(json.dumps(content)))
elif not res_elements is None:
for i,e in enumerate(res_elements):
content["elements"] = e
content["response_elements"] = e
resJson = extractRow(i, responseMsg, res_datatype, res_features, res_datadef)
content["response"] = resJson
print(str(json.dumps(content)))
Expand All @@ -70,17 +71,20 @@ def index():
# return 'Error processing input'


def extractRow(i:int,requestMsg: prediction_pb2.SeldonMessage,req_datatype: str,req_features: np.ndarray,req_datadef: prediction_pb2.SeldonMessage.data):
if req_datatype == "data":
datatyReq = requestMsg.data.WhichOneof("data_oneof")
else:
datatyReq = "ndarray"
def extractRow(i:int,requestMsg: prediction_pb2.SeldonMessage,req_datatype: str,req_features: np.ndarray,req_datadef: "prediction_pb2.SeldonMessage.data"):
datatyReq = "ndarray"
dataType = "tabular"
if len(req_features.shape) == 2:
dataReq = array_to_grpc_datadef(datatyReq, np.expand_dims(req_features[i], axis=0), req_datadef.names)
else:
dataReq = array_to_grpc_datadef(datatyReq, req_features, req_datadef.names)
if len(req_features.shape) > 2:
dataType="image"
else:
dataType="text"
dataReq = array_to_grpc_datadef(datatyReq, req_features, req_datadef.names)
requestMsg2 = prediction_pb2.SeldonMessage(data=dataReq, meta=requestMsg.meta)
reqJson = seldon_message_to_json(requestMsg2)
reqJson["dataType"] = dataType
return reqJson


Expand All @@ -93,13 +97,13 @@ def createElelmentsArray(X: np.ndarray,names: list):
for num, name in enumerate(names, start=0):
d[name] = X[num]
results.append(d)
elif len(X.shape) == 2:
elif len(X.shape) >= 2:
results = []
for i in range(X.shape[0]):
d = {}
for num, name in enumerate(names, start=0):
d[name] = X[i,num]
results.append(d)
d[name] = np.expand_dims(X[i,num], axis=0).tolist()
results.append(d)
return results

if __name__ == "__main__":
Expand Down