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.

client.py 1.9 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. """client example of add"""
  16. import numpy as np
  17. from mindspore_serving.client import Client
  18. def run_add_common():
  19. """invoke servable add method add_common"""
  20. client = Client("localhost", 5500, "add", "add_common")
  21. instances = []
  22. # instance 1
  23. x1 = np.asarray([[1, 1], [1, 1]]).astype(np.float32)
  24. x2 = np.asarray([[1, 1], [1, 1]]).astype(np.float32)
  25. instances.append({"x1": x1, "x2": x2})
  26. # instance 2
  27. x1 = np.asarray([[2, 2], [2, 2]]).astype(np.float32)
  28. x2 = np.asarray([[2, 2], [2, 2]]).astype(np.float32)
  29. instances.append({"x1": x1, "x2": x2})
  30. # instance 3
  31. x1 = np.asarray([[3, 3], [3, 3]]).astype(np.float32)
  32. x2 = np.asarray([[3, 3], [3, 3]]).astype(np.float32)
  33. instances.append({"x1": x1, "x2": x2})
  34. result = client.infer(instances)
  35. print(result)
  36. def run_add_cast():
  37. """invoke servable add method add_cast"""
  38. client = Client("localhost", 5500, "add", "add_cast")
  39. instances = []
  40. x1 = np.ones((2, 2), np.int32)
  41. x2 = np.ones((2, 2), np.int32)
  42. instances.append({"x1": x1, "x2": x2})
  43. result = client.infer(instances)
  44. print(result)
  45. if __name__ == '__main__':
  46. run_add_common()
  47. run_add_cast()

A lightweight and high-performance service module that helps MindSpore developers efficiently deploy online inference services in the production environment.