vehicle_attribute_recognition.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # copyright (c) 2024 PaddlePaddle Authors. All Rights Reserve.
  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. "Vehicle",
  24. "InferResult",
  25. "PRIMARY_OPERATIONS",
  26. ]
  27. INFER_ENDPOINT: Final[str] = "/vehicle-attribute-recognition"
  28. class InferRequest(BaseModel):
  29. image: str
  30. detThreshold: Optional[float] = None
  31. clsThreshold: Optional[
  32. Union[float, Dict[Union[Literal["default"], int], float], List[float]]
  33. ] = None
  34. class Attribute(BaseModel):
  35. label: str
  36. score: float
  37. class Vehicle(BaseModel):
  38. bbox: object_detection.BoundingBox
  39. attributes: List[Attribute]
  40. score: float
  41. class InferResult(BaseModel):
  42. vehicles: List[Vehicle]
  43. image: Optional[str] = None
  44. PRIMARY_OPERATIONS: Final[PrimaryOperations] = {
  45. "infer": (INFER_ENDPOINT, InferRequest, InferResult),
  46. }