MTerryJack commited on
Commit
6e3b47d
·
verified ·
1 Parent(s): 89bbcc2

Upload miner.py

Browse files
Files changed (1) hide show
  1. miner.py +16 -15
miner.py CHANGED
@@ -13,11 +13,12 @@ class BoundingBox(BaseModel):
13
  cls_id: int
14
  conf: float
15
 
 
16
  class TVFrameResult(BaseModel):
17
  frame_id: int
18
  boxes: list[BoundingBox]
19
- keypoints: list[tuple[int, int]]
20
-
21
 
22
  class Miner:
23
  """
@@ -31,25 +32,24 @@ class Miner:
31
  - have a `predict_batch` function with the inputs and outputs specified
32
  - be stored in a file called `miner.py` which lives in the root of the HFHub repo
33
  """
34
-
35
- def __init__(self, path_hf_repo:Path) -> None:
36
  """
37
  Loads all ML models from the repository.
38
  -----(Adjust as needed)----
39
 
40
  Args:
41
- path_hf_repo (Path):
42
  Path to the downloaded HuggingFace Hub repository
43
 
44
  Returns:
45
- None
46
  """
47
- self.bbox_model = YOLO(path_hf_repo/"football-player-detection.pt")
48
  print(f"✅ BBox Model Loaded")
49
- self.keypoints_model = YOLO(path_hf_repo/"football-pitch-detection.pt")
50
  print(f"✅ Keypoints Model Loaded")
51
 
52
-
53
  def __repr__(self) -> str:
54
  """
55
  Information about miner returned in the health endpoint
@@ -65,21 +65,21 @@ class Miner:
65
  n_keypoints: int,
66
  ) -> list[TVFrameResult]:
67
  """
68
- Miner prediction for a batch of images.
69
  Handles the orchestration of ML models and any preprocessing and postprocessing
70
  -----(Adjust as needed)----
71
 
72
  Args:
73
- batch_images (list[np.ndarray]):
74
  A list of images (as NumPy arrays) to process in this batch.
75
- offset (int):
76
- The frame number corresponding to the first image in the batch.
77
  Used to correctly index frames in the output results.
78
- n_keypoints (int):
79
  The number of keypoints expected for each frame in this challenge type.
80
 
81
  Returns:
82
- list[TVFrameResult]:
83
  A list of predictions for each image in the batch
84
  """
85
 
@@ -112,6 +112,7 @@ class Miner:
112
  if not hasattr(detection, "keypoints") or detection.keypoints is None:
113
  continue
114
  frame_keypoints: list[tuple[int, int]] = []
 
115
  for person_points in detection.keypoints.data:
116
  for x, y in person_points:
117
  frame_keypoints.append((int(x), int(y)))
 
13
  cls_id: int
14
  conf: float
15
 
16
+
17
  class TVFrameResult(BaseModel):
18
  frame_id: int
19
  boxes: list[BoundingBox]
20
+ keypoints: list[tuple[int, int]]
21
+
22
 
23
  class Miner:
24
  """
 
32
  - have a `predict_batch` function with the inputs and outputs specified
33
  - be stored in a file called `miner.py` which lives in the root of the HFHub repo
34
  """
35
+
36
+ def __init__(self, path_hf_repo: Path) -> None:
37
  """
38
  Loads all ML models from the repository.
39
  -----(Adjust as needed)----
40
 
41
  Args:
42
+ path_hf_repo (Path):
43
  Path to the downloaded HuggingFace Hub repository
44
 
45
  Returns:
46
+ None
47
  """
48
+ self.bbox_model = YOLO(path_hf_repo / "football-player-detection.pt")
49
  print(f"✅ BBox Model Loaded")
50
+ self.keypoints_model = YOLO(path_hf_repo / "football-pitch-detection.pt")
51
  print(f"✅ Keypoints Model Loaded")
52
 
 
53
  def __repr__(self) -> str:
54
  """
55
  Information about miner returned in the health endpoint
 
65
  n_keypoints: int,
66
  ) -> list[TVFrameResult]:
67
  """
68
+ Miner prediction for a batch of images.
69
  Handles the orchestration of ML models and any preprocessing and postprocessing
70
  -----(Adjust as needed)----
71
 
72
  Args:
73
+ batch_images (list[np.ndarray]):
74
  A list of images (as NumPy arrays) to process in this batch.
75
+ offset (int):
76
+ The frame number corresponding to the first image in the batch.
77
  Used to correctly index frames in the output results.
78
+ n_keypoints (int):
79
  The number of keypoints expected for each frame in this challenge type.
80
 
81
  Returns:
82
+ list[TVFrameResult]:
83
  A list of predictions for each image in the batch
84
  """
85
 
 
112
  if not hasattr(detection, "keypoints") or detection.keypoints is None:
113
  continue
114
  frame_keypoints: list[tuple[int, int]] = []
115
+ print(detection.keypoints.data)
116
  for person_points in detection.keypoints.data:
117
  for x, y in person_points:
118
  frame_keypoints.append((int(x), int(y)))