Upload folder using huggingface_hub
Browse files- .gitattributes +6 -0
- chute_config.yml +28 -0
- football_object_detection.onnx +3 -0
- football_pitch_template.png +0 -0
- hrnetv2_w48.yaml +35 -0
- inference.cpython-312-x86_64-linux-gnu.so +3 -0
- keypoint +3 -0
- keypoint_helper.cpython-312-x86_64-linux-gnu.so +3 -0
- keypoint_utils.py +49 -0
- miner.py +82 -0
- osnet_model.pth.tar-100 +3 -0
- template_caches_0 +3 -0
- template_caches_1 +3 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,9 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
template_caches_0 filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
template_caches_1 filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
keypoint filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
inference.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 40 |
+
keypoint_helper.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 41 |
+
osnet_model.pth.tar-100 filter=lfs diff=lfs merge=lfs -text
|
chute_config.yml
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Image:
|
| 2 |
+
from_base: parachutes/python:3.12
|
| 3 |
+
run_command:
|
| 4 |
+
- pip install --upgrade setuptools wheel
|
| 5 |
+
- pip install --index-url https://download.pytorch.org/whl/cu128 torch torchvision
|
| 6 |
+
- pip install "ultralytics==8.3.222" "opencv-python-headless" "numpy" "pydantic"
|
| 7 |
+
- pip install scikit-learn cryptography
|
| 8 |
+
- pip install onnxruntime-gpu numba scipy joblib psutil lz4
|
| 9 |
+
set_workdir: /app
|
| 10 |
+
readme: "Image for chutes"
|
| 11 |
+
|
| 12 |
+
NodeSelector:
|
| 13 |
+
gpu_count: 1
|
| 14 |
+
min_vram_gb_per_gpu: 24
|
| 15 |
+
min_memory_gb: 32
|
| 16 |
+
min_cpu_count: 16
|
| 17 |
+
exclude:
|
| 18 |
+
- "5090"
|
| 19 |
+
- b200
|
| 20 |
+
- h200
|
| 21 |
+
- mi300x
|
| 22 |
+
|
| 23 |
+
Chute:
|
| 24 |
+
timeout_seconds: 900
|
| 25 |
+
concurrency: 4
|
| 26 |
+
max_instances: 5
|
| 27 |
+
scaling_threshold: 0.5
|
| 28 |
+
shutdown_after_seconds: 96000
|
football_object_detection.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3cac99f021c260c71883e193609bf4aaef47e21bad3adadef2cc775fc1bd3ede
|
| 3 |
+
size 56988621
|
football_pitch_template.png
ADDED
|
hrnetv2_w48.yaml
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MODEL:
|
| 2 |
+
IMAGE_SIZE: [960, 540]
|
| 3 |
+
NUM_JOINTS: 58
|
| 4 |
+
PRETRAIN: ''
|
| 5 |
+
EXTRA:
|
| 6 |
+
FINAL_CONV_KERNEL: 1
|
| 7 |
+
STAGE1:
|
| 8 |
+
NUM_MODULES: 1
|
| 9 |
+
NUM_BRANCHES: 1
|
| 10 |
+
BLOCK: BOTTLENECK
|
| 11 |
+
NUM_BLOCKS: [4]
|
| 12 |
+
NUM_CHANNELS: [64]
|
| 13 |
+
FUSE_METHOD: SUM
|
| 14 |
+
STAGE2:
|
| 15 |
+
NUM_MODULES: 1
|
| 16 |
+
NUM_BRANCHES: 2
|
| 17 |
+
BLOCK: BASIC
|
| 18 |
+
NUM_BLOCKS: [4, 4]
|
| 19 |
+
NUM_CHANNELS: [48, 96]
|
| 20 |
+
FUSE_METHOD: SUM
|
| 21 |
+
STAGE3:
|
| 22 |
+
NUM_MODULES: 4
|
| 23 |
+
NUM_BRANCHES: 3
|
| 24 |
+
BLOCK: BASIC
|
| 25 |
+
NUM_BLOCKS: [4, 4, 4]
|
| 26 |
+
NUM_CHANNELS: [48, 96, 192]
|
| 27 |
+
FUSE_METHOD: SUM
|
| 28 |
+
STAGE4:
|
| 29 |
+
NUM_MODULES: 3
|
| 30 |
+
NUM_BRANCHES: 4
|
| 31 |
+
BLOCK: BASIC
|
| 32 |
+
NUM_BLOCKS: [4, 4, 4, 4]
|
| 33 |
+
NUM_CHANNELS: [48, 96, 192, 384]
|
| 34 |
+
FUSE_METHOD: SUM
|
| 35 |
+
|
inference.cpython-312-x86_64-linux-gnu.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2fffd06ea61f7df9576559fab7d12f037c892a84987d22e49852c9d263051aed
|
| 3 |
+
size 1089728
|
keypoint
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c415cc6005d769eaa02cb7c8e00d50ffca44034e58bffdf5f93033c8cb128564
|
| 3 |
+
size 264964689
|
keypoint_helper.cpython-312-x86_64-linux-gnu.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4ea79d9ad9a9433cb274dd6c67164c0eaaa2c6f26d4b8e0bd4d291309e93e23b
|
| 3 |
+
size 958672
|
keypoint_utils.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from numba import njit, prange
|
| 2 |
+
|
| 3 |
+
@njit(fastmath=True, cache=True)
|
| 4 |
+
def score_mask_numba_fast(pred, expected, ground, pixels_on_lines):
|
| 5 |
+
h, w = pred.shape
|
| 6 |
+
pp = 0
|
| 7 |
+
po = 0
|
| 8 |
+
|
| 9 |
+
for y in prange(h):
|
| 10 |
+
for x in range(w):
|
| 11 |
+
p_val = pred[y, x]
|
| 12 |
+
g_val = ground[y, x]
|
| 13 |
+
e_val = expected[y, x]
|
| 14 |
+
p = (p_val != 0) & (g_val != 0)
|
| 15 |
+
e = e_val != 0
|
| 16 |
+
pp += p
|
| 17 |
+
po += p & e
|
| 18 |
+
if pp == 0:
|
| 19 |
+
return 0.0
|
| 20 |
+
pr = pp - po
|
| 21 |
+
total = pixels_on_lines + pp - po
|
| 22 |
+
if total == 0 or pr * 10 > total * 9:
|
| 23 |
+
return 0.0
|
| 24 |
+
return po / (pixels_on_lines + 1e-8)
|
| 25 |
+
|
| 26 |
+
@njit(parallel=True, fastmath=True, cache=True, boundscheck=False)
|
| 27 |
+
def spmm_csc_optimized(data, indices, indptr, frames_T, out):
|
| 28 |
+
# frames_T is (P, F) -> C-contiguous (Row Major)
|
| 29 |
+
# out is (F, T) -> F-contiguous (Column Major)
|
| 30 |
+
|
| 31 |
+
F = frames_T.shape[1]
|
| 32 |
+
T = indptr.shape[0] - 1
|
| 33 |
+
|
| 34 |
+
# schedule='dynamic' handles uneven workloads (sparse matrices are rarely uniform)
|
| 35 |
+
for j in prange(T):
|
| 36 |
+
start = indptr[j]
|
| 37 |
+
end = indptr[j + 1]
|
| 38 |
+
|
| 39 |
+
# Inner loop: Iterate over non-zero pixels for this template
|
| 40 |
+
for k in range(start, end):
|
| 41 |
+
p = indices[k]
|
| 42 |
+
val_w = float(data[k]) # Cast uint8 to float once per pixel
|
| 43 |
+
|
| 44 |
+
# VECTORIZED LOOP:
|
| 45 |
+
# We are reading a contiguous row from frames_T (frames_T[p, :])
|
| 46 |
+
# and adding it to a contiguous column in out (out[:, j]).
|
| 47 |
+
# This allows the compiler to use AVX/SIMD instructions.
|
| 48 |
+
for i in range(F):
|
| 49 |
+
out[i, j] += frames_T[p, i] * val_w
|
miner.py
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
from typing import List, Tuple, Dict
|
| 5 |
+
import sys
|
| 6 |
+
import os
|
| 7 |
+
|
| 8 |
+
from numpy import ndarray
|
| 9 |
+
from pydantic import BaseModel
|
| 10 |
+
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
| 11 |
+
|
| 12 |
+
# from inference import predict_batch, load_model
|
| 13 |
+
import importlib.util
|
| 14 |
+
from pathlib import Path
|
| 15 |
+
|
| 16 |
+
def manual_import(name, filename):
|
| 17 |
+
"""
|
| 18 |
+
Manually loads a module (.so, .pyc, or .py) from a specific file path,
|
| 19 |
+
bypassing sys.meta_path import hooks.
|
| 20 |
+
"""
|
| 21 |
+
# Locate the file relative to the current miner.py
|
| 22 |
+
curr_dir = Path(__file__).parent
|
| 23 |
+
file_path = curr_dir / filename
|
| 24 |
+
|
| 25 |
+
if not file_path.exists():
|
| 26 |
+
raise FileNotFoundError(f"Could not find {file_path}")
|
| 27 |
+
|
| 28 |
+
# Load the spec directly from the file path
|
| 29 |
+
spec = importlib.util.spec_from_file_location(name, file_path)
|
| 30 |
+
if spec is None:
|
| 31 |
+
raise ImportError(f"Could not load spec for {name} from {file_path}")
|
| 32 |
+
|
| 33 |
+
# Create the module and register it in sys.modules
|
| 34 |
+
module = importlib.util.module_from_spec(spec)
|
| 35 |
+
sys.modules[name] = module
|
| 36 |
+
|
| 37 |
+
# Execute the module
|
| 38 |
+
spec.loader.exec_module(module)
|
| 39 |
+
return module
|
| 40 |
+
|
| 41 |
+
class BoundingBox(BaseModel):
|
| 42 |
+
x1: int
|
| 43 |
+
y1: int
|
| 44 |
+
x2: int
|
| 45 |
+
y2: int
|
| 46 |
+
cls_id: int
|
| 47 |
+
conf: float
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
class TVFrameResult(BaseModel):
|
| 51 |
+
frame_id: int
|
| 52 |
+
boxes: List[BoundingBox]
|
| 53 |
+
keypoints: List[Tuple[int, int]]
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
class Miner:
|
| 57 |
+
def __init__(self, path_hf_repo: Path) -> None:
|
| 58 |
+
print("model laoding")
|
| 59 |
+
self.health = 'Okay'
|
| 60 |
+
self.inference = None
|
| 61 |
+
self.path_hf_repo = path_hf_repo
|
| 62 |
+
self.is_start = False
|
| 63 |
+
|
| 64 |
+
def __repr__(self) -> str:
|
| 65 |
+
if self.inference is not None:
|
| 66 |
+
self.health = self.inference.gethealth()
|
| 67 |
+
return self.health
|
| 68 |
+
|
| 69 |
+
def predict_batch(self, batch_images: List[ndarray], offset: int, n_keypoints: int) -> List[TVFrameResult]:
|
| 70 |
+
if self.is_start == False:
|
| 71 |
+
self.is_start = True
|
| 72 |
+
return None
|
| 73 |
+
if self.inference is None:
|
| 74 |
+
self.inference = manual_import("inference", "inference.cpython-312-x86_64-linux-gnu.so")
|
| 75 |
+
self.inference.load_model(self.path_hf_repo)
|
| 76 |
+
|
| 77 |
+
results = self.inference.predict_batch(
|
| 78 |
+
batch_images,
|
| 79 |
+
offset,
|
| 80 |
+
n_keypoints,
|
| 81 |
+
)
|
| 82 |
+
return results
|
osnet_model.pth.tar-100
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:44237fa4d361334b9b49306b219218bd10c02d5ff153cbbcf3a6da38a0f7c192
|
| 3 |
+
size 40044571
|
template_caches_0
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:65c4e24f0f8fba28017303f31a4d90bd48f336ad6792b0663daeee1e3270f564
|
| 3 |
+
size 2818678329
|
template_caches_1
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0ad8be35655f379da083b732b79d4ec9adac61e947c79e97714b50e499040ee6
|
| 3 |
+
size 3493706738
|