pedestrian_attribute_recognition.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 Dict, Final, List, Optional, Union
  15. from pydantic import BaseModel
  16. from typing_extensions import Literal
  17. from ..infra.models import PrimaryOperations
  18. from .shared import object_detection
  19. __all__ = [
  20. "INFER_ENDPOINT",
  21. "InferRequest",
  22. "Attribute",
  23. "Pedestrian",
  24. "InferResult",
  25. "PRIMARY_OPERATIONS",
  26. ]
  27. INFER_ENDPOINT: Final[str] = "/pedestrian-attribute-recognition"
  28. class InferRequest(BaseModel):
  29. image: str
  30. detThreshold: Optional[float] = None
  31. visualize: Optional[bool] = None
  32. clsThreshold: Optional[
  33. Union[float, Dict[Union[Literal["default"], int], float], List[float]]
  34. ] = None
  35. class Attribute(BaseModel):
  36. label: str
  37. score: float
  38. class Pedestrian(BaseModel):
  39. bbox: object_detection.BoundingBox
  40. attributes: List[Attribute]
  41. score: float
  42. class InferResult(BaseModel):
  43. pedestrians: List[Pedestrian]
  44. image: Optional[str] = None
  45. PRIMARY_OPERATIONS: Final[PrimaryOperations] = {
  46. "infer": (INFER_ENDPOINT, InferRequest, InferResult),
  47. }