Upload 10 files
Browse files- .gitattributes +1 -0
- class_names.txt +1 -0
- element.yaml +6 -0
- environment.json +1 -0
- example.png +3 -0
- keypoints_metadata.json +1 -0
- main.py +105 -0
- model_type.json +4 -0
- pyproject.toml +11 -0
- uv.lock +0 -0
- weights.onnx +3 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ 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 |
+
example.png filter=lfs diff=lfs merge=lfs -text
|
class_names.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
court
|
element.yaml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: 0.1.0
|
| 2 |
+
element_type: PitchCalib
|
| 3 |
+
main: main.py
|
| 4 |
+
source: https://universe.roboflow.com/roboflow-jvuqo/basketball-court-detection-2
|
| 5 |
+
objects:
|
| 6 |
+
- court
|
environment.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"BATCH_SIZE": 8, "CACHE_PATH": "/train/cache", "DATASET_ID": "tT8apWsPavyvfZNc4fgN", "DATASET_LINK": "https://app.roboflow.com/ds/0066reL7dH?key=6NrcEsI7rH", "DATASET_OWNER": "GGqN5h3Ag5Msh1nOv8tjZvWDZpv1", "DATASET_VERSION_ID": "19", "ENDPOINT": "tT8apWsPavyvfZNc4fgN/19", "MODEL_NAME": "yolo11m-pose", "PREPROCESSING": "{\"auto-orient\":{\"enabled\":true},\"resize\":{\"enabled\":true,\"format\":\"Stretch to\",\"width\":\"640\",\"height\":\"640\"}}", "PROJECT": "roboflow-platform", "RESOLUTION": 640, "TRAINING_TIME": "2678400", "UID": "GGqN5h3Ag5Msh1nOv8tjZvWDZpv1", "COLORS": {"court": "#C7FC00"}}
|
example.png
ADDED
|
Git LFS Details
|
keypoints_metadata.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
[{"object_class": "court", "object_class_id": 0, "keypoints": {"0": "01", "1": "02", "2": "04", "3": "05", "4": "07", "5": "08", "6": "09", "7": "10", "8": "11", "9": "12", "10": "13", "11": "14", "12": "15", "13": "16", "14": "17", "15": "19", "16": "21", "17": "23", "18": "25", "19": "26", "20": "27", "21": "28", "22": "29", "23": "30", "24": "31", "25": "32", "26": "33", "27": "34", "28": "35", "29": "37", "30": "38", "31": "40", "32": "41"}}]
|
main.py
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse
|
| 2 |
+
import json
|
| 3 |
+
import sys
|
| 4 |
+
from io import BytesIO
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
from typing import Any, Dict, List
|
| 7 |
+
|
| 8 |
+
import numpy as np
|
| 9 |
+
from PIL import Image
|
| 10 |
+
from ultralytics import YOLO
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def load_keypoint_names(base_dir: Path) -> dict[int, str]:
|
| 14 |
+
metadata_path = base_dir / "keypoints_metadata.json"
|
| 15 |
+
if not metadata_path.exists():
|
| 16 |
+
return {}
|
| 17 |
+
try:
|
| 18 |
+
data = json.loads(metadata_path.read_text())
|
| 19 |
+
except Exception:
|
| 20 |
+
return {}
|
| 21 |
+
if not data:
|
| 22 |
+
return {}
|
| 23 |
+
keypoints = data[0].get("keypoints", {})
|
| 24 |
+
names: dict[int, str] = {}
|
| 25 |
+
for idx_str, label in keypoints.items():
|
| 26 |
+
try:
|
| 27 |
+
idx = int(idx_str)
|
| 28 |
+
except ValueError:
|
| 29 |
+
continue
|
| 30 |
+
names[idx] = str(label)
|
| 31 |
+
return names
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def load_image(frame: Any, base_dir: Path) -> Image.Image:
|
| 35 |
+
if isinstance(frame, (bytes, bytearray, memoryview)):
|
| 36 |
+
return Image.open(BytesIO(frame)).convert("RGB")
|
| 37 |
+
|
| 38 |
+
path = Path(str(frame))
|
| 39 |
+
if not path.is_absolute():
|
| 40 |
+
path = (Path.cwd() / path).resolve()
|
| 41 |
+
if not path.exists():
|
| 42 |
+
candidate = (base_dir / str(frame)).resolve()
|
| 43 |
+
if candidate.exists():
|
| 44 |
+
path = candidate
|
| 45 |
+
return Image.open(path).convert("RGB")
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def load_model(*_args: Any, **_kwargs: Any):
|
| 49 |
+
base_dir = Path(__file__).resolve().parent
|
| 50 |
+
model_path = base_dir / "weights.onnx"
|
| 51 |
+
if not model_path.exists():
|
| 52 |
+
return None
|
| 53 |
+
return YOLO(str(model_path), task="pose")
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def run_model(model, frame: "np.ndarray") -> List[Dict[str, Any]]:
|
| 57 |
+
base_dir = Path(__file__).resolve().parent
|
| 58 |
+
keypoint_names = load_keypoint_names(base_dir)
|
| 59 |
+
image = Image.fromarray(frame)
|
| 60 |
+
results = model(image)
|
| 61 |
+
outputs: List[Dict[str, Any]] = []
|
| 62 |
+
result = results[0]
|
| 63 |
+
if result.keypoints is None:
|
| 64 |
+
return outputs
|
| 65 |
+
|
| 66 |
+
keypoints_xy = result.keypoints.xy
|
| 67 |
+
for det_idx, points in enumerate(keypoints_xy):
|
| 68 |
+
point_items = []
|
| 69 |
+
for idx, xy in enumerate(points.tolist()):
|
| 70 |
+
label = keypoint_names.get(idx, str(idx))
|
| 71 |
+
point_items.append({"id": label, "x": float(xy[0]), "y": float(xy[1])})
|
| 72 |
+
outputs.append({"frame_idx": 0, "points": point_items})
|
| 73 |
+
|
| 74 |
+
return outputs
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
def build_parser() -> argparse.ArgumentParser:
|
| 78 |
+
parser = argparse.ArgumentParser(description="Run basketball court keypoint detection (YOLO pose ONNX).")
|
| 79 |
+
parser.add_argument(
|
| 80 |
+
"--stdin-raw",
|
| 81 |
+
action="store_true",
|
| 82 |
+
default=True,
|
| 83 |
+
help="Read raw image bytes from stdin.",
|
| 84 |
+
)
|
| 85 |
+
return parser
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
if __name__ == "__main__":
|
| 89 |
+
build_parser().parse_args()
|
| 90 |
+
|
| 91 |
+
base_dir = Path(__file__).resolve().parent
|
| 92 |
+
model = load_model()
|
| 93 |
+
if model is None:
|
| 94 |
+
print("[]")
|
| 95 |
+
sys.exit(0)
|
| 96 |
+
|
| 97 |
+
try:
|
| 98 |
+
image = load_image(sys.stdin.buffer.read(), base_dir)
|
| 99 |
+
except Exception:
|
| 100 |
+
print("[]")
|
| 101 |
+
sys.exit(0)
|
| 102 |
+
|
| 103 |
+
frame = np.array(image)
|
| 104 |
+
output = run_model(model, frame)
|
| 105 |
+
print(json.dumps(output))
|
model_type.json
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"project_task_type": "keypoint-detection",
|
| 3 |
+
"model_type": "yolov11m-pose"
|
| 4 |
+
}
|
pyproject.toml
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[project]
|
| 2 |
+
name = "basketball-court-detection-2-19"
|
| 3 |
+
version = "0.1.0"
|
| 4 |
+
requires-python = ">=3.11"
|
| 5 |
+
dependencies = [
|
| 6 |
+
"numpy>=1.26",
|
| 7 |
+
"pillow>=10.0",
|
| 8 |
+
"ultralytics>=8.0.0",
|
| 9 |
+
"onnx>=1.16",
|
| 10 |
+
"onnxruntime>=1.17",
|
| 11 |
+
]
|
uv.lock
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
weights.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9c00051bd207f5b76c6e492f3672be8dd7cce5a217ab271e971378fca057d26d
|
| 3 |
+
size 86282807
|