Multi-Frame Tennis Stroke Classification and Hit-Frame Detection
A shared pose-and-ball TCN that recognizes each player's tennis stroke and predicts the ball-contact frame, with explicit no-hit predictions, temporal event confirmation, and an INT8 deployment pipeline for RDK X5.

Tools & Skills
- TCN
- Pose Estimation
- Action Recognition
- PyTorch
- INT8 Quantization
- RDK X5
- Python
- NumPy
- OpenCV
- TensorBoard
- FFmpeg
- TorchScript
- ONNX
- ONNX Runtime
- RDK X5 Quantization
- HB_HBMRuntime
- COCO17 Keypoints
- Causal Convolutions
- Model Evaluation
- Multi-Task Learning
- Temporal Localization
- Ball Detection
- BoT-SORT
- OSNet
- My contribution
- Designed and implemented pose and ball feature extraction, the shared TCN with stroke and hit-frame heads, contact annotation review, joint training and evaluation, per-player event confirmation, and the INT8 deployment pipeline for RDK X5.
- Outcome
- A modular video pipeline that produces per-player stroke labels and source-aligned ball-contact events, with inspection tools and an edge deployment path that can evolve with product requirements.
Problem and product goal
Tennis analysis needs to identify what stroke a player made and when the racket contacted the ball. A single pose can resemble several phases of a swing or ordinary movement between strokes. A rolling forehand prediction also does not identify one contact event: the same swing can occupy several consecutive windows.
I extended the pose-based classifier into a joint stroke-classification and hit-frame model. It combines a player’s motion with ball observations, sharing one temporal convolutional network (TCN) between the two tasks. The current stroke vocabulary is forehand, backhand, and neutral; a separate output selects a contact frame or explicitly predicts no hit. The surrounding pipeline covers annotation review, training, continuous video inference, event confirmation, and edge deployment.
Challenges that shaped the design
| Challenge | Design response |
|---|---|
| A swing unfolds over several frames, and similar body motion may occur without contact. | Combine temporal pose features with ball motion and an explicit frame-or-no-hit decision. |
| Players move around the image and change apparent size. | Normalize poses by the player’s body position and height; retain global ball coordinates alongside player-relative offsets. |
| Body joints or the ball may disappear temporarily. | Carry confidence, observation masks, and presence flags so missing evidence is explicit. |
| Contact timing can be ambiguous at the instant of impact. | Let the hit head inspect a small amount of later context within the window and confirm candidates across overlapping windows. |
| A single contact can trigger predictions in several windows. | Aggregate evidence by player and original source frame, then consolidate nearby candidate peaks. |
| The pipeline must share edge compute with other perception tasks. | Reuse detector outputs, share the temporal backbone, and support INT8 export of the convolutional joint model. |
Numeric pose and ball features keep the temporal model compact while allowing the upstream detectors to improve independently. Recognition still depends on those observations and on maintaining the correct player identity.
Model architecture and reasoning
Pose and ball representation
The pose representation retains 69 channels per frame: normalized x/y, confidence, and an observation flag for each of 17 COCO joints, plus a presence flag. Coordinates are centered on the hips, with shoulders or the bounding-box center as fallbacks, and divided by player height. Missing joints briefly retain coordinates with zero confidence and observation flags; longer gaps become zero.
The joint model adds image-normalized ball position, confidence, and visibility. The relative-and-size configuration also includes ball offsets from the player’s body origin and observed wrists, plus detector-predicted ball diameter normalized by image height. These inputs describe the ball’s relationship to the swing while preserving its trajectory in image coordinates. Together they form 84 channels per position in the 16-position joint configuration. Diameter comes from the ball detector’s size head; bounding-box dimensions are not used as a size estimate.
Missing ball observations and unavailable relative anchors use zeros with validity masks rather than invented trajectories. Short player histories receive left zero padding. Training and inference share feature construction, normalization, and source-frame alignment.
One temporal backbone, two prediction heads
A pointwise convolution projects the features into a compact hidden representation. Residual blocks with dilated, causal temporal convolutions combine motion across the supplied history without downsampling it. Keeping a hidden state at every input position makes the same backbone useful for both window classification and frame localization.
The stroke head reads the newest hidden state and predicts forehand, backhand, or neutral. The hit head scores each temporal position and adds a learned no-hit score. For a window of length T, its softmax chooses among T frames plus no hit. This is one categorical contact decision per window; the stroke label does not force a hit prediction.
The convolutional hit head uses local context around each hidden position. With two-position lookahead, it can use observations immediately after a candidate contact, bounded by the supplied window. The backbone remains causal, but the complete contact decision deliberately allows later evidence. Left-padded positions are masked so they cannot become predicted contacts.
Joint training combines stroke and contact classification losses. Contact labels retain original source-frame indices through cropping and padding. Random crops move the contact within the window; a crop that excludes contact has a no-hit target even if it retains a stroke label. This teaches the distinction between recognizing swing motion and locating impact.
Inference pipeline
The person/pose model supplies player boxes and keypoints, while the ball detector supplies aligned position and diameter observations. Host inference uses BoT-SORT with OSNet appearance features to associate players and maintain separate histories. Racket-hand and distance estimates can appear in the display without becoming inputs to the selected joint TCN.
Expand the diagram to zoom in and explore.
Video inference and edge deployment
Each player receives rolling stroke and hit/no-hit predictions with track IDs, warmup status, and original source-frame indices. The ball detector processes non-overlapping three-frame groups and reuses all three temporal outputs. This avoids repeating detector inference for every sliding triplet while still updating pose and TCN inference for every real frame. Incomplete groups repeat the last image and discard padded outputs.
A separate confirmation layer averages a frame’s hit and no-hit probabilities across windows covering that frame. A candidate needs at least one selecting window and stronger average hit evidence than no-hit evidence. Nearby peaks are consolidated per player, allowing later negative evidence to cancel an isolated positive and reducing duplicate events from the same contact.
Playback and export are buffered so confirmed events appear on their original frames. Ball grouping adds acquisition delay, and overlapping-window confirmation adds further delay; this is not an instantaneous contact notification. Overlays show stroke-colored hit badges and contact markers, while structured exports retain raw window predictions and confirmed events for inspection.
For RDK X5, the convolutional joint model is lowered to equivalent height-one Conv2d operations, preserving the causal backbone and the hit head’s local-context padding. TorchScript and ONNX exports feed INT8 calibration and compilation. The standalone board application combines pose, ball, stroke, and contact inference through the device runtimes, including HB_HBMRuntime for the TCN. Its per-player association is simpler than the host’s BoT-SORT/OSNet tracker.
Both output heads are checked through conversion and runtime comparison. Changes to upstream detectors or feature construction require matching training inputs, retraining where needed, and renewed export/device verification; historical board checks do not validate every later pipeline revision.
Evaluation, inspection, and iteration
I built tools to inspect behavior throughout development. Annotation review shows player selection, poses, ball observations, and explicitly labeled contact frames together. TensorBoard, per-epoch predictions, and an offline dashboard expose both tasks. Frame-level review compares predicted and annotated contact positions and isolates false hits, missed contacts, timing errors, and stroke confusions.
Evaluation separates clip-level localization from replay through the continuous event-confirmation filter. This checks whether a model’s window predictions become useful events after aggregation. Deployment verification compares the original, exported, quantized, and device outputs for both heads. The improvement cycle is to inspect failures, refine labels or inputs, retrain, and recheck behavior through video inference and deployment.
Evolving with product requirements
The current classes are an initial product scope. Adding stroke classes means extending the labels and stroke head, updating review, evaluation, and deployment code that assumes the current vocabulary, and retraining and validating the resulting model. The shared backbone and separate contact output allow stroke vocabulary and event timing to evolve together.
Feature construction, temporal modeling, and event confirmation remain separate components. The observation window, ball representation, and confirmation policy can be reconsidered as product requirements change, using the same inspection workflow.
The hit head selects at most one contact per window; the confirmation layer combines these predictions across a stream. Stroke boundaries, rally interpretation, and reliable higher-level counting require additional product logic and validation beyond these contact events.
Technology
Python, PyTorch, NumPy, OpenCV, COCO17 pose features, ball detection, causal temporal convolutions, multi-task learning, temporal localization, BoT-SORT/OSNet tracking, TensorBoard, FFmpeg, TorchScript, ONNX Runtime, INT8 post-training quantization, and RDK X5 inference.
Evidence & demonstration
Demos & project media

Pose and ball features feed a shared TCN to classify tennis strokes and locate the ball-contact frame, with an explicit no-hit output.
Video description
The demo presents joint tennis stroke classification and ball-contact-frame detection. Pose and ball features pass through a shared temporal backbone, which outputs a stroke class and a contact frame or an explicit no-hit prediction.


