meaculpitt commited on
Commit
52a0bb5
Β·
verified Β·
1 Parent(s): 359b624

scorevision: push artifact

Browse files
Files changed (2) hide show
  1. __pycache__/miner.cpython-312.pyc +0 -0
  2. miner.py +31 -18
__pycache__/miner.cpython-312.pyc ADDED
Binary file (41 kB). View file
 
miner.py CHANGED
@@ -479,16 +479,29 @@ class Miner:
479
  ))
480
  return out
481
 
482
- # ── Person preprocessing (stretch resize) ──────────────────────────────
 
 
 
 
 
 
 
 
 
 
 
 
 
483
 
484
  def _per_preprocess(self, image_bgr):
485
- rgb = cv2.cvtColor(image_bgr, cv2.COLOR_BGR2RGB)
486
- resized = cv2.resize(rgb, (self.per_w, self.per_h))
487
- x = resized.astype(np.float32) / 255.0
488
- x = np.transpose(x, (2, 0, 1))[None, ...]
489
- return x
490
 
491
- def _per_decode(self, raw, oh, ow, conf_thresh):
492
  pred = raw[0]
493
  if pred.ndim != 2:
494
  return np.empty((0, 4)), np.empty(0)
@@ -501,9 +514,10 @@ class Miner:
501
  boxes, confs = pred[keep, :4], confs[keep]
502
  if len(boxes) == 0:
503
  return np.empty((0, 4)), np.empty(0)
504
- sx, sy = ow / float(self.per_w), oh / float(self.per_h)
505
- boxes[:, 0] *= sx; boxes[:, 2] *= sx
506
- boxes[:, 1] *= sy; boxes[:, 3] *= sy
 
507
  boxes = np.clip(boxes, 0, [[ow, oh, ow, oh]])
508
  return boxes, confs
509
 
@@ -518,19 +532,18 @@ class Miner:
518
  boxes, confs = pred[keep, :4], confs[keep]
519
  if len(boxes) == 0:
520
  return np.empty((0, 4)), np.empty(0)
521
- sx, sy = ow / float(self.per_w), oh / float(self.per_h)
522
  cx, cy, bw, bh = boxes[:, 0], boxes[:, 1], boxes[:, 2], boxes[:, 3]
523
- x1 = np.clip((cx - bw / 2) * sx, 0, ow)
524
- y1 = np.clip((cy - bh / 2) * sy, 0, oh)
525
- x2 = np.clip((cx + bw / 2) * sx, 0, ow)
526
- y2 = np.clip((cy + bh / 2) * sy, 0, oh)
527
  return np.stack([x1, y1, x2, y2], axis=1), confs
528
 
529
  def _per_run_pass(self, image_bgr, conf_thresh):
530
  oh, ow = image_bgr.shape[:2]
531
- inp = self._per_preprocess(image_bgr)
532
  raw = self.per_session.run(None, {self.per_input_name: inp})[0]
533
- return self._per_decode(raw, oh, ow, conf_thresh)
534
 
535
  def _infer_person(self, image_bgr):
536
  oh, ow = image_bgr.shape[:2]
@@ -713,4 +726,4 @@ class Miner:
713
  ).start()
714
 
715
  return results
716
- # Miner v3.1 β€” repo-split + YOLO26s person 960px 20260331
 
479
  ))
480
  return out
481
 
482
+ # ── Person preprocessing (letterbox) ──────────────────────────────────
483
+
484
+ def _per_letterbox(self, img):
485
+ h, w = img.shape[:2]
486
+ r = min(self.per_h / h, self.per_w / w)
487
+ nw, nh = int(round(w * r)), int(round(h * r))
488
+ img_r = cv2.resize(img, (nw, nh), interpolation=cv2.INTER_LINEAR)
489
+ dw, dh = self.per_w - nw, self.per_h - nh
490
+ pl, pt = dw // 2, dh // 2
491
+ img_p = cv2.copyMakeBorder(
492
+ img_r, pt, dh - pt, pl, dw - pl,
493
+ cv2.BORDER_CONSTANT, value=(114, 114, 114),
494
+ )
495
+ return img_p, r, pl, pt
496
 
497
  def _per_preprocess(self, image_bgr):
498
+ img_p, ratio, pl, pt = self._per_letterbox(image_bgr)
499
+ rgb = cv2.cvtColor(img_p, cv2.COLOR_BGR2RGB)
500
+ inp = rgb.astype(np.float32) / 255.0
501
+ inp = np.ascontiguousarray(inp.transpose(2, 0, 1)[np.newaxis])
502
+ return inp, ratio, pl, pt
503
 
504
+ def _per_decode(self, raw, ratio, pl, pt, oh, ow, conf_thresh):
505
  pred = raw[0]
506
  if pred.ndim != 2:
507
  return np.empty((0, 4)), np.empty(0)
 
514
  boxes, confs = pred[keep, :4], confs[keep]
515
  if len(boxes) == 0:
516
  return np.empty((0, 4)), np.empty(0)
517
+ boxes[:, 0] = (boxes[:, 0] - pl) / ratio
518
+ boxes[:, 2] = (boxes[:, 2] - pl) / ratio
519
+ boxes[:, 1] = (boxes[:, 1] - pt) / ratio
520
+ boxes[:, 3] = (boxes[:, 3] - pt) / ratio
521
  boxes = np.clip(boxes, 0, [[ow, oh, ow, oh]])
522
  return boxes, confs
523
 
 
532
  boxes, confs = pred[keep, :4], confs[keep]
533
  if len(boxes) == 0:
534
  return np.empty((0, 4)), np.empty(0)
 
535
  cx, cy, bw, bh = boxes[:, 0], boxes[:, 1], boxes[:, 2], boxes[:, 3]
536
+ x1 = np.clip((cx - bw / 2 - pl) / ratio, 0, ow)
537
+ y1 = np.clip((cy - bh / 2 - pt) / ratio, 0, oh)
538
+ x2 = np.clip((cx + bw / 2 - pl) / ratio, 0, ow)
539
+ y2 = np.clip((cy + bh / 2 - pt) / ratio, 0, oh)
540
  return np.stack([x1, y1, x2, y2], axis=1), confs
541
 
542
  def _per_run_pass(self, image_bgr, conf_thresh):
543
  oh, ow = image_bgr.shape[:2]
544
+ inp, ratio, pl, pt = self._per_preprocess(image_bgr)
545
  raw = self.per_session.run(None, {self.per_input_name: inp})[0]
546
+ return self._per_decode(raw, ratio, pl, pt, oh, ow, conf_thresh)
547
 
548
  def _infer_person(self, image_bgr):
549
  oh, ow = image_bgr.shape[:2]
 
726
  ).start()
727
 
728
  return results
729
+ # Miner v3.2 β€” letterbox person preprocessing + YOLO26s 960px 20260331