Spaces:
Running on T4
Running on T4
Download baseball_batting/diagnostics.py from modventures/baseball-engine: direct link, hf CLI and curl.
- Browser
- Download file 2.21 kB
-
https://huggingface.co/spaces/modventures/baseball-engine/resolve/main/baseball_batting/diagnostics.py
- Command line
-
hf download hf://spaces/modventures/baseball-engine/baseball_batting/diagnostics.py
-
curl -L -o diagnostics.py https://huggingface.co/spaces/modventures/baseball-engine/resolve/main/baseball_batting/diagnostics.py
2.21 kB
| """Separate frame processing from actual observation and measurement coverage.""" | |
| import numpy as np | |
| from .contracts import RTMW_CORE | |
| SUPPORTED = {"manual", "image_supported", "model_inferred"} | |
| def observation_summary(observations): | |
| counts = {"body_frames": 0, "body_landmarks": 0, "person_frames": 0, | |
| "bat_box_frames": 0, "bat_endpoint_frames": 0, "ball_frames": 0} | |
| frames = observations["frames"] | |
| for frame in frames: | |
| points = np.asarray(frame["body_points"], float) | |
| supported = [j for j in RTMW_CORE.values() if frame["body_states"][j] in SUPPORTED | |
| and np.isfinite(points[j]).all()] | |
| counts["body_frames"] += bool(supported) | |
| counts["body_landmarks"] += len(supported) | |
| counts["person_frames"] += frame["person"] is not None | |
| counts["bat_box_frames"] += any(p["class_id"] == 34 for p in frame["proposals"]) | |
| bat = frame["bat"] | |
| counts["bat_endpoint_frames"] += bool(bat["points"] is not None | |
| and all(s in SUPPORTED for s in bat["states"]) | |
| and np.isfinite(np.asarray(bat["points"], float)).all()) | |
| ball = frame["ball"] | |
| counts["ball_frames"] += bool(ball["point"] is not None and ball["state"] in SUPPORTED | |
| and np.isfinite(np.asarray(ball["point"], float)).all()) | |
| failures = {name: status for name, status in observations["branch_status"].items() | |
| if status["status"] in {"failed", "failed_preflight"}} | |
| any_support = any(counts[k] for k in ("body_frames", "bat_endpoint_frames", "ball_frames")) | |
| state = "complete" if any_support else ("failed" if failures else "empty") | |
| if state == "failed": | |
| message = "Analysis failed: vision models could not run and no usable observations were produced." | |
| elif state == "empty": | |
| message = "No usable body, bat or ball observations were produced. Check model setup and subject visibility." | |
| else: | |
| message = "Observation coverage is available; individual measurements still require their evidence gates." | |
| return {"status": state, "frame_count": len(frames), **counts, | |
| "model_failures": failures, "message": message} | |