tarto2 commited on
Commit
996e082
·
1 Parent(s): d90e4a2

change object detection model

Browse files
Files changed (2) hide show
  1. best.pt +3 -0
  2. miner.py +38 -30
best.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ae707480215c937e905a7236c1f72867231e8e475eab4e91bebd252aa64236d8
3
+ size 5455642
miner.py CHANGED
@@ -61,10 +61,18 @@ class Miner:
61
  SMALL_RATIO_MAX: float = 0.50
62
  SINGLE_PLAYER_HUE_PIVOT: float = 90.0
63
 
 
 
 
 
 
 
 
 
64
  def __init__(self, path_hf_repo: Path) -> None:
65
- print(path_hf_repo / "objdetect.pt")
66
- self.bbox_model = YOLO(path_hf_repo / "objdetect.pt")
67
- print(" BBox Model (objdetect.pt) Loaded")
68
  device = "cuda" if torch.cuda.is_available() else "cpu"
69
  # model_kp_path = path_hf_repo / "SV_kp.engine"
70
  # model_kp = torch_tensorrt.load(model_kp_path)
@@ -255,7 +263,7 @@ class Miner:
255
  y1=int(y1),
256
  x2=int(x2),
257
  y2=int(y2),
258
- cls_id=int(cls_id),
259
  conf=float(conf),
260
  )
261
  )
@@ -264,32 +272,32 @@ class Miner:
264
  best_ball = max(footballs, key=lambda b: b.conf)
265
  boxes = [bb for bb in boxes if int(bb.cls_id) != 0]
266
  boxes.append(best_ball)
267
- boxes = self.suppress_quasi_total_containment(boxes)
268
- boxes = self.suppress_small_contained(boxes)
269
- img_bgr = batch_images[frame_idx_in_batch]
270
- player_indices: List[int] = []
271
- player_feats: List[np.ndarray] = []
272
- for i, bb in enumerate(boxes):
273
- if int(bb.cls_id) == 2:
274
- hs = self._hs_feature_from_roi(img_bgr, bb)
275
- player_indices.append(i)
276
- player_feats.append(hs)
277
- cluster_centers = None
278
- n_players = len(player_feats)
279
- if n_players >= 2:
280
- feats = np.vstack(player_feats)
281
- labels, centers = self._assign_players_two_clusters(feats)
282
- order = np.argsort(centers[:, 0])
283
- centers = centers[order]
284
- remap = {old_idx: new_idx for new_idx, old_idx in enumerate(order)}
285
- labels = np.vectorize(remap.get)(labels)
286
- cluster_centers = centers
287
- for idx_in_list, lbl in zip(player_indices, labels):
288
- boxes[idx_in_list].cls_id = 6 if int(lbl) == 0 else 7
289
- elif n_players == 1:
290
- hue, _ = player_feats[0]
291
- boxes[player_indices[0]].cls_id = 6 if float(hue) < self.SINGLE_PLAYER_HUE_PIVOT else 7
292
- self._reclass_extra_goalkeepers(img_bgr, boxes, cluster_centers)
293
  bboxes[offset + frame_idx_in_batch] = boxes
294
 
295
  pitch_batch_size = min(self.pitch_batch_size, len(batch_images))
 
61
  SMALL_RATIO_MAX: float = 0.50
62
  SINGLE_PLAYER_HUE_PIVOT: float = 90.0
63
 
64
+ CLS_MAP = {
65
+ 0: 0,
66
+ 1: 1,
67
+ 2: 6,
68
+ 3: 7,
69
+ 4: 3,
70
+ }
71
+
72
  def __init__(self, path_hf_repo: Path) -> None:
73
+ print(path_hf_repo / "best.pt")
74
+ self.bbox_model = YOLO(path_hf_repo / "best.pt")
75
+ print(" BBox Model (best.pt) Loaded")
76
  device = "cuda" if torch.cuda.is_available() else "cpu"
77
  # model_kp_path = path_hf_repo / "SV_kp.engine"
78
  # model_kp = torch_tensorrt.load(model_kp_path)
 
263
  y1=int(y1),
264
  x2=int(x2),
265
  y2=int(y2),
266
+ cls_id=int(self.CLS_MAP[int(cls_id)]),
267
  conf=float(conf),
268
  )
269
  )
 
272
  best_ball = max(footballs, key=lambda b: b.conf)
273
  boxes = [bb for bb in boxes if int(bb.cls_id) != 0]
274
  boxes.append(best_ball)
275
+ # boxes = self.suppress_quasi_total_containment(boxes)
276
+ # boxes = self.suppress_small_contained(boxes)
277
+ # img_bgr = batch_images[frame_idx_in_batch]
278
+ # player_indices: List[int] = []
279
+ # player_feats: List[np.ndarray] = []
280
+ # for i, bb in enumerate(boxes):
281
+ # if int(bb.cls_id) == 2:
282
+ # hs = self._hs_feature_from_roi(img_bgr, bb)
283
+ # player_indices.append(i)
284
+ # player_feats.append(hs)
285
+ # cluster_centers = None
286
+ # n_players = len(player_feats)
287
+ # if n_players >= 2:
288
+ # feats = np.vstack(player_feats)
289
+ # labels, centers = self._assign_players_two_clusters(feats)
290
+ # order = np.argsort(centers[:, 0])
291
+ # centers = centers[order]
292
+ # remap = {old_idx: new_idx for new_idx, old_idx in enumerate(order)}
293
+ # labels = np.vectorize(remap.get)(labels)
294
+ # cluster_centers = centers
295
+ # for idx_in_list, lbl in zip(player_indices, labels):
296
+ # boxes[idx_in_list].cls_id = 6 if int(lbl) == 0 else 7
297
+ # elif n_players == 1:
298
+ # hue, _ = player_feats[0]
299
+ # boxes[player_indices[0]].cls_id = 6 if float(hue) < self.SINGLE_PLAYER_HUE_PIVOT else 7
300
+ # self._reclass_extra_goalkeepers(img_bgr, boxes, cluster_centers)
301
  bboxes[offset + frame_idx_in_batch] = boxes
302
 
303
  pitch_batch_size = min(self.pitch_batch_size, len(batch_images))