/
object_detection.py
55 lines (42 loc) · 1.53 KB
/
object_detection.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# Inference code generated from the JSON schema spec in @huggingface/tasks.
#
# See:
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
from dataclasses import dataclass
from typing import Any, Optional
from .base import BaseInferenceType
@dataclass
class ObjectDetectionParameters(BaseInferenceType):
"""Additional inference parameters
Additional inference parameters for Object Detection
"""
threshold: Optional[float] = None
"""The probability necessary to make a prediction."""
@dataclass
class ObjectDetectionInput(BaseInferenceType):
"""Inputs for Object Detection inference"""
inputs: Any
"""The input image data"""
parameters: Optional[ObjectDetectionParameters] = None
"""Additional inference parameters"""
@dataclass
class ObjectDetectionBoundingBox(BaseInferenceType):
"""The predicted bounding box. Coordinates are relative to the top left corner of the input
image.
"""
xmax: int
xmin: int
ymax: int
ymin: int
@dataclass
class ObjectDetectionOutputElement(BaseInferenceType):
"""Outputs of inference for the Object Detection task"""
box: ObjectDetectionBoundingBox
"""The predicted bounding box. Coordinates are relative to the top left corner of the input
image.
"""
label: str
"""The predicted label for the bounding box"""
score: float
"""The associated score / probability"""