You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

ms_client_test_call.py 1.7 kB

5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # Copyright 2020 Huawei Technologies Co., Ltd
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # ============================================================================
  15. import grpc
  16. import numpy as np
  17. import ms_service_pb2
  18. import ms_service_pb2_grpc
  19. def run():
  20. channel = grpc.insecure_channel('localhost:50051')
  21. stub = ms_service_pb2_grpc.MSServiceStub(channel)
  22. # request = ms_service_pb2.EvalRequest()
  23. # request.name = 'haha'
  24. # response = stub.Eval(request)
  25. # print("ms client received: " + response.message)
  26. request = ms_service_pb2.PredictRequest()
  27. request.data.tensor_shape.dims.extend([32, 1, 32, 32])
  28. request.data.tensor_type = ms_service_pb2.MS_FLOAT32
  29. request.data.data = (np.ones([32, 1, 32, 32]).astype(np.float32) * 0.01).tobytes()
  30. request.label.tensor_shape.dims.extend([32])
  31. request.label.tensor_type = ms_service_pb2.MS_INT32
  32. request.label.data = np.ones([32]).astype(np.int32).tobytes()
  33. result = stub.Test(request)
  34. #result_np = np.frombuffer(result.result.data, dtype=np.float32).reshape(result.result.tensor_shape.dims)
  35. print("ms client test call received: ")
  36. #print(result_np)
  37. if __name__ == '__main__':
  38. run()