client.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/usr/bin/env python
  2. # Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. import argparse
  16. import pprint
  17. import sys
  18. from paddlex_hps_client import triton_request, utils
  19. from tritonclient import grpc as triton_grpc
  20. OUTPUT_IMAGE_PATH = "out.jpg"
  21. def main():
  22. parser = argparse.ArgumentParser()
  23. parser.add_argument("--image", type=str, required=True)
  24. parser.add_argument("--no-visualization", action="store_true")
  25. parser.add_argument("--url", type=str, default="localhost:8001")
  26. args = parser.parse_args()
  27. client = triton_grpc.InferenceServerClient(args.url)
  28. input_ = {"image": utils.prepare_input_file(args.image)}
  29. if args.no_visualization:
  30. input_["visualize"] = False
  31. output = triton_request(client, "human-keypoint-detection", input_)
  32. if output["errorCode"] != 0:
  33. print(f"Error code: {output['errorCode']}", file=sys.stderr)
  34. print(f"Error message: {output['errorMsg']}", file=sys.stderr)
  35. sys.exit(1)
  36. result = output["result"]
  37. utils.save_output_file(result["image"], OUTPUT_IMAGE_PATH)
  38. print(f"Output image saved at {OUTPUT_IMAGE_PATH}")
  39. print("\nDetected persons:")
  40. pprint.pp(result["persons"])
  41. if __name__ == "__main__":
  42. main()