human_keypoint_detection.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved.
  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. from typing import Final, List, Optional, Tuple
  15. from pydantic import BaseModel
  16. from typing_extensions import TypeAlias
  17. from ..infra.models import PrimaryOperations
  18. from .shared import object_detection
  19. __all__ = [
  20. "INFER_ENDPOINT",
  21. "InferRequest",
  22. "KeyPoint",
  23. "Person",
  24. "InferResult",
  25. "PRIMARY_OPERATIONS",
  26. ]
  27. KeyPoint: TypeAlias = Tuple[float, float, float]
  28. INFER_ENDPOINT: Final[str] = "/human-keypoint-detection"
  29. class InferRequest(BaseModel):
  30. image: str
  31. detThreshold: Optional[float] = None
  32. visualize: Optional[bool] = None
  33. class Person(BaseModel):
  34. bbox: object_detection.BoundingBox
  35. kpts: List[KeyPoint]
  36. detScore: float
  37. kptScore: float
  38. class InferResult(BaseModel):
  39. persons: List[Person]
  40. image: Optional[str] = None
  41. PRIMARY_OPERATIONS: Final[PrimaryOperations] = {
  42. "infer": (INFER_ENDPOINT, InferRequest, InferResult),
  43. }