๐Ÿ…ฟ Parkospace โ€” AI Parking Space Detector

A lightweight MobileNetV2-based keypoint detector that automatically detects the 4 corners of a parking space rectangle in a photo, estimates real-world dimensions, and calculates rental pricing. Built for the Parkospace platform.


๐Ÿง  What It Does

  • ๐Ÿ“ธ Takes a photo of a parking space
  • ๐Ÿ” Detects the 4 corner keypoints of the space (TL, TR, BR, BL)
  • ๐Ÿ“ Estimates real-world dimensions in metres (using 2-photo perspective method)
  • ๐Ÿ’ฐ Calculates Hourly / Daily / Monthly pricing automatically
  • โœ๏ธ Lets users interactively adjust the rectangle (resize + move)

๐Ÿ—๏ธ Model Architecture

Property Value
Architecture MobileNetV2 + Regression Head
Input (B, 3, 224, 224) โ€” normalized RGB
Output (B, 8) โ€” 4 corners (x, y) normalized to [0, 1]
Corner order TL โ†’ TR โ†’ BR โ†’ BL
Loss function Wing Loss
Total parameters ~3.4M
Model size ~13 MB
Inference speed < 30ms on CPU

๐Ÿ“ File Structure

parkospace/
โ”œโ”€โ”€ parkospace_colab.ipynb   # Complete Colab notebook (train + test + infer)
โ”œโ”€โ”€ generate_data.py         # Synthetic parking image generator
โ”œโ”€โ”€ model.py                 # CNN model definition
โ”œโ”€โ”€ train.py                 # Training script
โ”œโ”€โ”€ infer.py                 # Inference + interactive editor + pricing
โ”œโ”€โ”€ upload_to_hf.py          # HuggingFace Hub upload script
โ”œโ”€โ”€ requirements.txt         # Dependencies
โ””โ”€โ”€ README.md

๐Ÿš€ Quickstart

Option 1 โ€” Google Colab (Recommended)

Open parkospace_colab.ipynb in Google Colab, switch to T4 GPU, and run all cells top to bottom. No setup needed.

Option 2 โ€” Run Locally

1. Clone and install

git clone https://github.com/your-username/parkospace-detector
cd parkospace-detector
pip install -r requirements.txt

2. Generate synthetic training data

python generate_data.py --out data --n 5000

3. Train the model

python train.py --data data --epochs 30 --batch 32

4. Run inference on an image

python infer.py --checkpoint checkpoints/best.pt --img parking.jpg

5. Dual-image dimension estimation

python infer.py \
  --checkpoint checkpoints/best.pt \
  --length_img  photo_from_length_side.jpg \
  --breadth_img photo_from_breadth_side.jpg

๐Ÿ Python API

from model import ParkingSpaceDetector
from infer  import load_model, detect, calculate_pricing

# Load trained model
model = load_model("checkpoints/best.pt")

# Detect parking space corners
import cv2
img = cv2.imread("parking.jpg")
det = detect(model, img)

print("Corners (pixels):", det.corners_px)
# [[x0,y0], [x1,y1], [x2,y2], [x3,y3]]  โ†’  TL, TR, BR, BL

# Calculate pricing
pricing = calculate_pricing(area_m2=15.0)
print(pricing)
# {
#   "hourly_inr":  50.0,
#   "daily_inr":   300.0,
#   "monthly_inr": 150.0,
#   "area_m2":     15.0
# }

๐Ÿ“ Dual-Image Dimension Estimation

For accurate real-world measurements without any special equipment:

  1. Photo 1 โ€” Stand at the length side, photograph across the width
  2. Photo 2 โ€” Stand at the breadth side, photograph along the length
from infer import load_model, estimate_dimensions_dual
import cv2

model      = load_model("checkpoints/best.pt")
length_img  = cv2.imread("from_length_side.jpg")
breadth_img = cv2.imread("from_breadth_side.jpg")

dims = estimate_dimensions_dual(model, length_img, breadth_img)
# {
#   "length_m":  5.2,
#   "breadth_m": 2.6,
#   "area_m2":   13.52
# }

๐Ÿ’ฐ Pricing Logic

Type Formula Default
Hourly Fixed โ‚น50
Daily Fixed โ‚น300
Monthly area_mยฒ ร— โ‚น10 e.g. 15mยฒ โ†’ โ‚น150

All prices are configurable โ€” pass custom values to calculate_pricing().


๐Ÿ‹๏ธ Training Details

Setting Value
Dataset 5,000 synthetic images (OpenCV generated)
Train / Val split 85% / 15%
Optimizer AdamW (lr=1e-3, weight_decay=1e-4)
Scheduler Cosine Annealing
Phase 1 (epochs 1โ€“10) Backbone frozen, head only
Phase 2 (epochs 11โ€“30) Last 5 backbone layers unfrozen
Augmentations Color jitter, shadows, noise, blur, brightness
Best val corner error < 10px on 224ร—224 images

Training Curves

Training takes ~10 minutes on a free Colab T4 GPU.


๐Ÿ“ฆ Requirements

torch>=2.0.0
torchvision>=0.15.0
opencv-python-headless>=4.7.0
numpy>=1.24.0
tqdm>=4.65.0
matplotlib>=3.7.0
Pillow>=9.5.0
huggingface_hub>=0.16.0

Install all:

pip install -r requirements.txt

๐Ÿ”ฎ Roadmap

  • Fine-tune on real parking space photos
  • Add support for non-rectangular spaces (polygons)
  • ONNX export for browser-based inference
  • Integrate with Parkospace owner dashboard
  • Occupied / available space detection
  • Multi-space detection in a single image

๐Ÿค Contributing

Contributions are welcome! If you have real parking space photos you'd like to contribute to improve the model, please open an issue or pull request.

  1. Fork the repository
  2. Create your feature branch: git checkout -b feature/my-feature
  3. Commit your changes: git commit -m 'Add my feature'
  4. Push to the branch: git push origin feature/my-feature
  5. Open a Pull Request

๐Ÿ“„ License

MIT License

Copyright (c) 2025 Parkospace

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

๐Ÿ‘ค Author

UmeshAdabala โ€” Parkospace

Built with โค๏ธ for making parking smarter in India ๐Ÿ‡ฎ๐Ÿ‡ณ

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Spaces using UmeshAdabala/RectArea_Parkospace 2