Spaces:
Sleeping
Sleeping
| title: Car Detection | |
| emoji: π’ | |
| colorFrom: gray | |
| colorTo: yellow | |
| sdk: docker | |
| pinned: false | |
| license: cc-by-nc-nd-4.0 | |
| short_description: car-counting | |
| Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference | |
| # Parking - Aerial Photo Car Detection | |
| Detect and count cars in aerial/satellite photography using an RF-DETR object detection model, served via a FastAPI backend with a Preact frontend. | |
| ## Architecture | |
| ``` | |
| training/ Model training, export, and inference scripts (RF-DETR + ONNX) | |
| server/ FastAPI backend β serves ONNX model predictions | |
| frontend/ Preact + Vite + TypeScript UI | |
| ``` | |
| ## Quick Start | |
| ### Prerequisites | |
| - Python 3.11+ | |
| - Node.js 18+ | |
| - Trained ONNX model at `training/exported_models/inference_model.sim.onnx` | |
| ### Backend | |
| ```bash | |
| pip install -r server/requirements.txt | |
| uvicorn server.main:app --reload --port 8000 | |
| ``` | |
| ### Frontend | |
| ```bash | |
| cd frontend | |
| npm install | |
| npm run dev | |
| ``` | |
| Open http://localhost:5173, upload an aerial image, and view detection results. | |
| ## API | |
| ### `POST /detect` | |
| Multipart form upload. Returns detected cars with annotated and heatmap images. | |
| | Parameter | Type | Default | Description | | |
| |-------------|-------|---------|--------------------------| | |
| | `file` | file | β | JPEG or PNG image | | |
| | `threshold` | float | 0.5 | Confidence threshold 0β1 | | |
| Response: | |
| ```json | |
| { | |
| "car_count": 47, | |
| "detections": [{"bbox": [x1, y1, x2, y2], "score": 0.97}, ...], | |
| "annotated_image": "data:image/jpeg;base64,...", | |
| "heatmap_image": "data:image/jpeg;base64,..." | |
| } | |
| ``` | |
| ### `GET /health` | |
| Returns `{"status": "ok", "model_loaded": true}`. | |
| ## Deployment | |
| The backend and frontend are deployed separately so the page loads instantly (static CDN) while the model runs server-side. | |
| ### Backend β Hugging Face Spaces | |
| 1. Create a new Space at [huggingface.co/new-space](https://huggingface.co/new-space) with **Docker** SDK | |
| 2. Clone the Space repo and copy in the required files: | |
| ```bash | |
| git clone https://huggingface.co/spaces/YOUR_USER/YOUR_SPACE | |
| cd YOUR_SPACE | |
| cp /path/to/parking/Dockerfile . | |
| cp -r /path/to/parking/server ./server | |
| mkdir -p training/exported_models | |
| cp /path/to/parking/training/exported_models/inference_model.sim.onnx ./training/exported_models/ | |
| git add . && git commit -m "Initial deploy" && git push | |
| ``` | |
| 3. The Space will build the Docker image and start serving at `https://YOUR_USER-YOUR_SPACE.hf.space` | |
| ### Frontend β Vercel | |
| 1. Push the `frontend/` directory to a GitHub repo (or use the full project repo) | |
| 2. Import the project at [vercel.com/new](https://vercel.com/new) | |
| 3. Set **Root Directory** to `frontend` | |
| 4. Add the environment variable: | |
| - `VITE_API_URL` = `https://YOUR_USER-YOUR_SPACE.hf.space` | |
| 5. Deploy β Vercel auto-detects Vite and builds it | |
| ## Model | |
| - Architecture: RF-DETR (medium) | |
| - Single class: car | |
| - Trained on aerial parking lot imagery in YOLO format | |
| - Exported to ONNX with graph simplification | |
| - Training scripts and data live under `training/` | |