CoolFace
Modelpublic

Cracked-ANJ/CourtKeyNet

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes26downloads
Model Card

<div align="center"> <img src="assets/teasser.png" alt="CourtKeyNet Banner" width="100%">

CourtKeyNet: A Novel Octave-Based Architecture for Precision Court Detection

Adithya N Raj

![Paper](https://www.sciencedirect.com/science/article/pii/S2666827026000496) ![GitHub](https://github.com/adithyanraj03/CourtKeyNet) ![Dataset](https://github.com/adithyanraj03/Paper09Data-Set_CourtKeyNet) ![License](LICENSE) ![SafeTensors](https://huggingface.co/docs/safetensors)

</div>


Model Summary

CourtKeyNet is a lightweight deep learning architecture for precision court keypoint detection in sports videos. It detects 4 corner keypoints of badminton and tennis courts from a single image, enabling downstream applications like court homography estimation, match statistics generation, and automated broadcasting systems.

Published in Machine Learning with Applications (Elsevier), 2026.

Key Features

  • โ€”๐ŸŽฏ 99.99% PCK and 99.67% IoU on the fine-tuned model
  • โ€”โšก Lightweight and fast โ€” efficient architecture for real-time use
  • โ€”๐Ÿ”ฌ Octave Feature Extractor โ€” Multi-frequency feature decomposition for capturing fine court details and global structural context
  • โ€”๐ŸŽฑ Polar Transform Attention โ€” Boundary detection in polar coordinates for precise court line localization
  • โ€”๐Ÿ“ Geometric Consistency Loss โ€” Ensures structurally valid quadrilateral outputs
  • โ€”๐Ÿธ Supports both badminton and tennis court detection

Model Variants

VariantFileFormatVal LossPCK (%)IoU (%)Description
CourtKeyNet-Basepretrained/courtkeynet_base.safetensorsSafeTensors0.097799.0994.33Pre-trained on 140k+ images from scratch
CourtKeyNet-Finetuned โญfinetuned/courtkeynet_finetuned.safetensorsSafeTensors0.001399.9999.67Fine-tuned on 7k+ clean annotated images
Recommendation: Use the fine-tuned variant for best results. The pre-trained base model is provided for researchers who wish to fine-tune on their own custom court datasets.

Quick Start

1. Download Weights

bash
# Install huggingface CLI
pip install "huggingface_hub[cli]"

# Download the full repository
huggingface-cli download Cracked-ANJ/CourtKeyNet --local-dir ./courtkeynet-weights

# Or download only the fine-tuned model (recommended)
huggingface-cli download Cracked-ANJ/CourtKeyNet finetuned/courtkeynet_finetuned.safetensors --local-dir ./courtkeynet-weights

2. Run Inference

For inference, training, and fine-tuning scripts, use the full source code from the [GitHub Repository](https://github.com/adithyanraj03/CourtKeyNet):

bash
# Clone the source code
git clone https://github.com/adithyanraj03/CourtKeyNet.git
cd CourtKeyNet

# Install dependencies
pip install -r requirements.txt

# Run Inference Studio (GUI)
cd courtkeynet
python inference.py
The Inference Studio provides a complete GUI with image/video/webcam support, confidence scoring, and real-time visualization.

Architecture

<div align="center"> <img src="assets/architecture.png" alt="CourtKeyNet Architecture" width="80%"> </div>

<details> <summary style="font-size: 1.2em; font-weight: bold; cursor: pointer;">๐Ÿ” How Confidence Detection Works (Visual Explanation)</summary>

How Confidence Detection Works

The model (CourtKeyNet) works like this:

[image]

Problem: It has no "court detector" โ€” it assumes every image IS a court!


What the Model Actually Outputs Internally

When you run model(image), it returns a dictionary with these components:

python
outputs = {
    'heatmaps': Tensor[B, 4, 160, 160],      # 4 gaussian peaks (one per corner)
    'kpts_init': Tensor[B, 4, 2],            # Initial keypoints from heatmaps
    'kpts_refined': Tensor[B, 4, 2],         # Final refined keypoints
    'features': Tensor[B, 256, 20, 20]       # Feature maps (optional)
}
Visualization of Heatmap Output

For a real court image:

text
Heatmap for Corner 0 (Top-Left):

[image]

For a non-court image (e.g., random person):

text
Heatmap for Corner 0:

[image]


3 Confidence Metrics
1๏ธโƒฃ Heatmap Peak Confidence (Primary Signal)

What it measures: How "peaky" the heatmap is

python
max_values = heatmaps.max(dim=(2,3))  # Find highest value in each heatmap
conf_heatmap = max_values.mean()      # Average across 4 corners

Visual comparison:

[image]


2๏ธโƒฃ Heatmap Entropy (Uncertainty)

What it measures: How "spread out" the probability is

python
# Entropy = -ฮฃ(p * log(p))
# Low entropy = focused (good)
# High entropy = random noise (bad)

Visual comparison:

[image]


3๏ธโƒฃ Geometric Validity (Shape Check)

What it checks: Does the quad look like a real court?

text
Checklist:
โœ“ Are corners in correct positions? (TL upper-left, BR lower-right)
โœ“ Is the quad convex? (no crossed lines)
โœ“ Is the area reasonable? (not too tiny, not entire image)
โœ“ Is aspect ratio court-like? (not a thin line)

Visual examples:

[image]

</details>


Training Details

Pre-training (from scratch)

ParameterValue
Dataset140,000+ badminton & tennis court images
Epochs158 (early stopping, patience=20)
Best Epoch138
OptimizerAdamW
Learning Rate5e-5 (cosine schedule)
Batch Size47
Image Size640ร—640
Mixed Precisionโœ“ FP16
HardwareNVIDIA RTX 5090 (32GB)

Fine-tuning

ParameterValue
Base ModelPre-trained CourtKeyNet-Base (epoch 138)
Dataset7,000+ precisely annotated clean images
Epochs79 (early stopping, patience=20)
Best Epoch59
Learning Rate1e-4
Batch Size48
Geometric LossEnabled (edge + diagonal + angle constraints)

Evaluation Results

Fine-tuned Model (Recommended)

MetricScore
PCK (Percentage of Correct Keypoints)99.99%
IoU (Intersection over Union)99.67%
Validation Loss0.0013

Pre-trained Base Model

MetricScore
PCK99.09%
IoU94.33%
Validation Loss0.0977

Training Metrics

<div align="center"> <img src="assets/training_metrics.png" alt="Training Metrics" width="100%"> <p><em>Pre-training metrics across 158 epochs showing loss convergence and PCK/IoU progression</em></p> </div>

<div align="center"> <img src="assets/finetune_detail.png" alt="Fine-tuning Detail" width="100%"> <p><em>Fine-tuning convergence: rapid loss decrease with PCK reaching 99.99% and IoU reaching 99.67%</em></p> </div>

Validation Samples

<div align="center"> <table> <tr> <td align="center"><strong>Epoch 1 (Early Fine-tuning)</strong></td> <td align="center"><strong>Epoch 79 (Final)</strong></td> </tr> <tr> <td><img src="assets/valsampleearly.jpg" alt="Early Validation" width="100%"></td> <td><img src="assets/valsamplefinal.jpg" alt="Final Validation" width="100%"></td> </tr> </table> <p><em>Red = Predicted court boundary | Green = Ground truth | Yellow dots = Keypoints</em></p> </div>


Fine-tuning on Custom Data

To fine-tune CourtKeyNet on your own court dataset (any sport):

bash
# 1. Clone the source code
git clone https://github.com/adithyanraj03/CourtKeyNet.git
cd CourtKeyNet

# 2. Download weights
huggingface-cli download Cracked-ANJ/CourtKeyNet pretrained/courtkeynet_base.pt --local-dir ./weights

# 3. Fine-tune
cd courtkeynet
python finetune.py
Note: Fine-tuning requires only 5,000โ€“7,000 clean annotated images. Training from scratch requires 140,000+ images.

Intended Use

โœ… Appropriate Uses

  • โ€”Badminton and tennis court detection in sports videos
  • โ€”Court homography estimation for tactical analysis
  • โ€”Generating match statistics from broadcast footage
  • โ€”Automated camera calibration for sports broadcasting
  • โ€”Academic research in sports video analysis

โš ๏ธ Limitations

  • โ€”Trained specifically on badminton and tennis courts; other court types may require fine-tuning
  • โ€”Expects single-court images; multi-court scenes are not supported
  • โ€”Performance may degrade on heavily occluded courts or extreme camera angles
  • โ€”The model detects 4 outer corners only (not inner court lines)

Citation

If you use CourtKeyNet in your research, please cite:

Paper: CourtKeyNet: A novel octave-based architecture for precision badminton court detection with geometric constraints DOI: 10.1016/j.mlwa.2026.100884

bibtex
@article{NRAJ2026100884,
  title     = {CourtKeyNet: A novel octave-based architecture for precision badminton court detection with geometric constraints},
  journal   = {Machine Learning with Applications},
  volume    = {24},
  pages     = {100884},
  year      = {2026},
  issn      = {2666-8270},
  doi       = {https://doi.org/10.1016/j.mlwa.2026.100884},
  url       = {https://www.sciencedirect.com/science/article/pii/S2666827026000496},
  author    = {Adithya N Raj and Prethija G.}
}

License

This project is released under the MIT License, suitable for both academic and commercial use.

Contact

For questions or collaboration opportunities: adithyanraj03@gmail.com