YAML Metadata
Warning:
empty or missing yaml metadata in repo card
(https://huggingface.co/docs/hub/model-cards#model-card-metadata)
Faster R-CNN Package Detector
This repository contains a Faster R-CNN model trained to detect packages at front doors using the Roboflow dataset. The project includes dataset downloading, model training, evaluation, and deployment to the Hugging Face Model Hub.
π Features
- π Dataset Download: Uses Roboflow API to fetch the dataset in YOLO format.
- ποΈ Model Training: Implements Faster R-CNN with ResNet-50 backbone for object detection.
- π Evaluation: Computes Intersection over Union (IoU) to measure model accuracy.
- βοΈ Model Deployment: Uploads trained model to Hugging Face Hub for easy sharing and reuse.
π Installation
1οΈβ£ Setup Environment
Ensure you have Python 3 installed, and set up dependencies using:
pip install torch torchvision roboflow tqdm huggingface_hub
2οΈβ£ Clone the Repository
git clone https://huggingface.co/johngunerli/fasterrcnn-package-detector
cd fasterrcnn-package-detector
π Dataset
The dataset is fetched from Roboflow using:
from roboflow import Roboflow
rf = Roboflow(api_key="YOUR_API_KEY")
project = rf.workspace("package-detection").project("package-at-front-door")
version = project.version(2)
dataset = version.download("yolov5")
ποΈ Training
To train the model on the downloaded dataset, run:
python train_model.py
Training Configuration
- Backbone: ResNet-50
- Optimizer: SGD (lr=0.005, momentum=0.9, weight_decay=0.0005)
- Scheduler: StepLR (step_size=3, gamma=0.1)
- Epochs: 10
π― Evaluation
The model evaluates performance using IoU scores:
val_loss, avg_iou = evaluate_model(model, valid_loader, device)
print(f"Validation Loss: {val_loss:.4f}, Avg IoU: {avg_iou:.4f}")
βοΈ Uploading to Hugging Face
To upload the trained model to Hugging Face, run:
from huggingface_hub import Repository
repo_id = "your-username/fasterrcnn-package-detector"
repo_dir = "./fasterrcnn-package-detector"
repo = Repository(repo_dir, clone_from=repo_id)
torch.save(model.state_dict(), "model_package.pth")
repo.push_to_hub(commit_message="Upload Faster R-CNN trained model")
π Model Performance
Epoch | Train Loss | Avg IoU |
---|---|---|
1 | 146.32 | 0.7974 |
2 | 123.80 | 0.7757 |
3 | 117.00 | 0.7855 |
4 | 107.56 | 0.8124 |
5 | 107.14 | 0.8129 |
6 | 103.35 | 0.8012 |
7 | 102.27 | 0.8132 |
8 | 102.88 | 0.8197 |
9 | 100.50 | 0.8244 |
10 | 103.23 | 0.8214 |
π Usage
To use the trained model for inference:
import torch
import torchvision
from torchvision.models.detection.faster_rcnn import FastRCNNPredictor
def get_model(num_classes):
model = torchvision.models.detection.fasterrcnn_resnet50_fpn(pretrained=False)
in_features = model.roi_heads.box_predictor.cls_score.in_features
model.roi_heads.box_predictor = FastRCNNPredictor(in_features, num_classes)
return model
model = get_model(2)
model.load_state_dict(torch.load("model_package.pth", map_location="cpu"))
model.eval()
Inference Providers
NEW
This model isn't deployed by any Inference Provider.
π
Ask for provider support