tonyassi / foot-detection

huggingface.co
Total runs: 0
24-hour runs: 0
7-day runs: 0
30-day runs: 0
Model's Last Updated: May 13 2025
object-detection

Introduction of foot-detection

Model Details of foot-detection

🦶 Faster R-CNN Foot Detection Model

by Tony Assi

This model detects feet or shoes in an image using a fine-tuned Faster R-CNN model from Torchvision.

It was trained on a small custom dataset of foot annotations and is intended as a starting point for foot/shoe detection in street, fashion, or movement-based applications.

Web demo: Hugging Face Spaces


🧠 Model Details
  • Base model: fasterrcnn_resnet50_fpn (pretrained on COCO)
  • Fine-tuned on 40 images of feet/shoes
  • Class labels:
    • 1 : foot/shoe
  • Bounding box outputs with confidence scores
  • Optimized for CPU (but works with MPS and CUDA)

⚡️ Quick Start

To download this repository:

git clone https://github.com/tonyassi/FootDetection.git
cd FootDetection

Install:

pip install -r requirements.txt

Usage:

from FootDetection import FootDetection
from PIL import Image

# Initialize model (first run will auto-download weights)
foot_detection = FootDetection("cpu")  # "cuda" for GPU  or "mps" for Apple Silicon

# Load image
img = Image.open("image.jpg").convert("RGB")

# Run detection
results = foot_detection.detect(img, threshold=0.1)
print(results)

# Draw boxes
img_with_boxes = foot_detection.draw_boxes(img)
img_with_boxes.show()
img_with_boxes.save("annotated_image.jpg")

📦 Usage
pip install torch torchvision pillow huggingface_hub
import os
import torch
import torchvision
from torchvision.models.detection.faster_rcnn import FastRCNNPredictor
from PIL import Image, ImageDraw
from torchvision.transforms import functional as F
from huggingface_hub import hf_hub_download

# ===== CONFIG =====
device = torch.device("cpu")  # or "mps" if stable
checkpoint_dir = "checkpoints"
checkpoint_file = "fasterrcnn_foot.pth"
local_path = os.path.join(checkpoint_dir, checkpoint_file)

# ===== Ensure Checkpoint Exists =====
if not os.path.exists(local_path):
    os.makedirs(checkpoint_dir, exist_ok=True)
    print("Downloading model from Hugging Face...")
    local_path = hf_hub_download(
        repo_id="tonyassi/foot-detection",
        filename=checkpoint_file,
        local_dir=checkpoint_dir
    )

# ===== Load Model =====
model = torchvision.models.detection.fasterrcnn_resnet50_fpn(weights="DEFAULT")
in_features = model.roi_heads.box_predictor.cls_score.in_features
model.roi_heads.box_predictor = FastRCNNPredictor(in_features, 2)
model.load_state_dict(torch.load(local_path, map_location=device))
model.to(device)
model.eval()

# ===== Function: Foot Detection =====
def foot_detection(image, threshold=0.1):
    """Takes a PIL image, returns bounding boxes + scores above threshold"""
    image_tensor = F.to_tensor(image).unsqueeze(0).to(device)
    with torch.no_grad():
        outputs = model(image_tensor)[0]

    boxes = []
    scores = []
    for box, score in zip(outputs["boxes"], outputs["scores"]):
        if score >= threshold:
            boxes.append(box.tolist())
            scores.append(score.item())

    return {
        "boxes": boxes,
        "scores": scores
    }

# ===== Function: Draw Bounding Boxes =====
def draw_bounding_box(image, detection):
    """Draws boxes and scores on a copy of the image"""
    image_copy = image.copy()
    draw = ImageDraw.Draw(image_copy)

    for box, score in zip(detection["boxes"], detection["scores"]):
        x0, y0, x1, y1 = box
        draw.rectangle([x0, y0, x1, y1], outline="red", width=3)
        draw.text((x0, y0), f"{score:.2f}", fill="red")

    return image_copy


from PIL import Image

# ==== Load and prepare image ====
image_path = "test.jpg"  # replace with your image path
image = Image.open(image_path).convert("RGB")

# ==== Run detection ====
detections = foot_detection(image, threshold=0.3)

# ==== Draw results ====
result_image = draw_bounding_box(image, detections)
result_image.show()  # or result_image.save("output.jpg")

Runs of tonyassi foot-detection on huggingface.co

0
Total runs
0
24-hour runs
0
3-day runs
0
7-day runs
0
30-day runs

More Information About foot-detection huggingface.co Model

More foot-detection license Visit here:

https://choosealicense.com/licenses/mit

foot-detection huggingface.co

foot-detection huggingface.co is an AI model on huggingface.co that provides foot-detection's model effect (), which can be used instantly with this tonyassi foot-detection model. huggingface.co supports a free trial of the foot-detection model, and also provides paid use of the foot-detection. Support call foot-detection model through api, including Node.js, Python, http.

foot-detection huggingface.co Url

https://huggingface.co/tonyassi/foot-detection

tonyassi foot-detection online free

foot-detection huggingface.co is an online trial and call api platform, which integrates foot-detection's modeling effects, including api services, and provides a free online trial of foot-detection, you can try foot-detection online for free by clicking the link below.

tonyassi foot-detection online free url in huggingface.co:

https://huggingface.co/tonyassi/foot-detection

foot-detection install

foot-detection is an open source model from GitHub that offers a free installation service, and any user can find foot-detection on GitHub to install. At the same time, huggingface.co provides the effect of foot-detection install, users can directly use foot-detection installed effect in huggingface.co for debugging and trial. It also supports api for free installation.

foot-detection install url in huggingface.co:

https://huggingface.co/tonyassi/foot-detection

Url of foot-detection

foot-detection huggingface.co Url

Provider of foot-detection huggingface.co

tonyassi
ORGANIZATIONS

Other API from tonyassi

huggingface.co

Total runs: 11
Run Growth: -2
Growth Rate: -18.18%
Updated:March 20 2024
huggingface.co

Total runs: 10
Run Growth: 7
Growth Rate: 70.00%
Updated:February 27 2024
huggingface.co

Total runs: 3
Run Growth: 2
Growth Rate: 66.67%
Updated:August 15 2023
huggingface.co

Total runs: 2
Run Growth: -2
Growth Rate: -100.00%
Updated:November 08 2023
huggingface.co

Total runs: 1
Run Growth: -5
Growth Rate: -500.00%
Updated:November 08 2023
huggingface.co

Total runs: 0
Run Growth: 0
Growth Rate: 0.00%
Updated:March 11 2026