kodokan.recognizer#
Technique recognition for applications: top-k guesses with inspectable scores (#3).
kodokan.recognize holds the research tools (features, LOO evaluation, metrics).
This module is the application facade over them:
TechniqueRecognizer— fit on pooled demo descriptors, thenrecognize()returns aRecognition: the top-kGuesses and the score of every technique (the intermediate vector a UIcan show).
recognize_segments()— offline video: detect the throws in a whole pose sequence and recognize each.ThrowDetector— a rolling pose buffer that reports each throw once its segment has closed;LiveRecognizerrecognizes them (live stream mode).
Scores are a softmax over negative distances to each technique’s centroid, in the train-standardized (and, when scikit-learn is installed, LDA-projected) descriptor space, with distances in units of the typical within-technique spread (measured leave-one-out, as a held-out demo would see it). They rank techniques and sum to 1; they are not calibrated probabilities. The LDA projection is still fit on every training demo, so with few demos per technique the spread stays optimistic.
>>> rng = np.random.default_rng(0)
>>> X = np.vstack([rng.normal(c, 0.3, size=(5, 4)) for c in (0.0, 3.0, 6.0)])
>>> y = np.repeat(["seoi-nage", "o-goshi", "uchi-mata"], 5)
>>> rec = TechniqueRecognizer(method="centroid").fit(X, y)
>>> r = rec.recognize(np.full(4, 3.1), k=2)
>>> r.guesses[0].technique, len(r.guesses), round(sum(r.scores.values()), 6)
('o-goshi', 2, 1.0)
Module Attributes
|
|
Smoothed motion energy (keypoint speed, px per analysed frame) a throw must reach; below it a "segment" is pose jitter, which quantile thresholds alone would accept. |
Functions
|
Leave-one-out (or leave-one-group-out) top-k accuracy of |
|
Throw windows by motion energy ( |
|
The default |
|
Offline video mode: every detected throw in |
Classes
|
One candidate technique and its score (higher is more likely). |
|
Live mode: each throw a |
|
The top-k guesses, best first, and every technique's score. |
|
Fit on pooled descriptors; recognize with top-k guesses and the full score vector. |
|
A rolling pose buffer that reports each throw once, after its segment closes. |
- kodokan.recognizer.DFLT_MIN_PEAK_ACTIVITY = 3.0#
Smoothed motion energy (keypoint speed, px per analysed frame) a throw must reach; below it a “segment” is pose jitter, which quantile thresholds alone would accept.
- kodokan.recognizer.Featurizer#
(pose_seq, start_s, end_s) -> fixed-length descriptorof one throw window.alias of
Callable[[PoseSequence,float,float],ndarray]
- class kodokan.recognizer.Guess(technique, score)[source]#
Bases:
objectOne candidate technique and its score (higher is more likely).
- class kodokan.recognizer.LiveRecognizer(recognizer, *, fps, k=3, featurize=<function pooled_demo_descriptor>, **detector_kwargs)[source]#
Bases:
objectLive mode: each throw a
ThrowDetectorreports, recognized once.push()takes one frame ((P, 17, 3)keypoints) and returns(segment, recognition)for the throws that closed with it. Detector options (buffer_s,close_after_s,segmenter,width,height) pass through.
- class kodokan.recognizer.Recognition(guesses, scores=dict())[source]#
Bases:
objectThe top-k guesses, best first, and every technique’s score.
- class kodokan.recognizer.TechniqueRecognizer(*, method='lda', temperature=1.0)[source]#
Bases:
objectFit on pooled descriptors; recognize with top-k guesses and the full score vector.
- Parameters:
- fit(X, y)[source]#
Fit on pooled descriptors
X(one row per demo) and technique labelsy.- Return type:
- fit_demos(feature_seqs, labels, *, levels=(1, 2, 4))[source]#
Fit on per-frame feature sequences (e.g.
kodokan.recognize.demo_feature()).- Return type:
- recognize(x, *, k=3)[source]#
Top-
kguesses (best first) and the full score vector for one descriptor.- Return type:
- class kodokan.recognizer.ThrowDetector(*, fps, width=0, height=0, buffer_s=20.0, close_after_s=1.0, segmenter=<function motion_segments>)[source]#
Bases:
objectA rolling pose buffer that reports each throw once, after its segment closes.
Push one frame at a time (
(P, 17, 3)keypoints, as inPoseSequence).push()returns(buffer, segment)for the throws that closed with that frame. A segment counts as closed when it ends at leastclose_after_sbefore the newest frame; the buffer keeps the lastbuffer_sseconds of pushed frames (atfpsframes a second: push every analysed frame, or pass the analysed rate asfps). A segment that mostly overlaps a throw already reported is that throw.
- kodokan.recognizer.loo_top_k_accuracy(X, y, *, ks=(1, 3, 5), groups=None, method='lda')[source]#
Leave-one-out (or leave-one-group-out) top-k accuracy of
TechniqueRecognizer.The share of held-out demos whose true technique is among the recognizer’s
kbest guesses, for eachkinks: the number the top-k app (#3) shows, next to top-1 fromkodokan.recognize.loo_pooled_predict(). Passgroups(e.g. the source clip of each demo) to hold out whole groups. A held-out demo whose technique is absent from its training fold counts as a miss.>>> rng = np.random.default_rng(0) >>> X = np.vstack([rng.normal(c, 1.0, size=(4, 3)) for c in (0.0, 1.0, 2.0)]) >>> y = np.repeat(["a", "b", "c"], 4) >>> acc = loo_top_k_accuracy(X, y, ks=(1, 3), method="centroid") >>> acc[3] 1.0
- kodokan.recognizer.motion_segments(pose_seq, *, min_peak_activity=3.0, **segment_kwargs)[source]#
Throw windows by motion energy (
kodokan.segment.find_segments()), keeping only those whose peak energy reachesmin_peak_activity(an absolute floor: the hysteresis thresholds are quantiles, so an idle buffer still has “segments”).
- kodokan.recognizer.pooled_demo_descriptor(pose_seq, start_s, end_s, *, mode='tori_angles_pos', levels=(1, 2, 4))[source]#
The default
Featurizer: per-frame demo features, temporal-pyramid pooled.- Return type:
ndarray