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

Faster protobuffer to numpy conversion in python wrapper #278

Merged
merged 2 commits into from
Nov 1, 2018
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,5 @@ examples/models/onnx_resnet50/resnet.onnx
#openapi
engine/src/main/resources/static/seldon.json
api-frontend/src/main/resources/static/seldon.json
wrappers/python/seldon.json

8 changes: 7 additions & 1 deletion wrappers/python/microservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,13 @@ def array_to_rest_datadef(array,names,original_datadef):
def grpc_datadef_to_array(datadef):
data_type = datadef.WhichOneof("data_oneof")
if data_type == "tensor":
features = np.array(datadef.tensor.values).reshape(datadef.tensor.shape)
sz = np.prod(datadef.tensor.shape) # get number of float64 entries
c = datadef.tensor.SerializeToString() # get bytes
# create array from packed entries which are at end of bytes - assumes same endianness
features = np.frombuffer(memoryview(c[-(sz*8):]), dtype=np.float64, count=sz, offset=0)
features = features.reshape(datadef.tensor.shape)
# Previous method which is slower
# features = np.array(datadef.tensor.values).reshape(datadef.tensor.shape)
elif data_type == "ndarray":
features = np.array(datadef.ndarray)
else:
Expand Down