CrowdVision is an end-to-end web application for crowd counting using state-of-the-art deep learning models. It offers two complementary approaches:
| Method | Model | Description |
|---|---|---|
| Density Map | CSRNet | Generates heat map showing crowd density distribution |
| Point Localization | P2PNet | Detects and marks individual head positions |
- π¨ Modern Web Interface - Clean, responsive UI with mint green theme
- π€ Drag & Drop Upload - Easy image upload or use sample images
- π₯ Dual Detection Methods - Choose between density map or point localization
- β‘ Optimized Models - Dynamic quantization for efficient CPU inference
- ποΈ Adjustable Threshold - Fine-tune detection sensitivity for P2PNet
- π Visual Results - Interactive visualization with download option
- Python 3.10+
- pip package manager
# Clone the repository
git clone https://github.com/RedEye1605/CrowdCounting.git
cd CrowdCounting
# Install dependencies
pip install -r requirements.txt
# Run server
python -m uvicorn app.main:app --reload --host 0.0.0.0 --port 8000Open http://localhost:8000 in your browser.
# Build image
docker build -t crowdvision .
# Run container
docker run -p 8080:8080 crowdvision# Install flyctl
# Windows: powershell -Command "irm https://fly.io/install.ps1 | iex"
# macOS/Linux: curl -L https://fly.io/install.sh | sh
# Login and deploy
flyctl auth login
flyctl launch --no-deploy
flyctl deploy- Create a new Space at huggingface.co/spaces
- Select Gradio as the SDK
- Clone your Space and copy files:
git clone https://huggingface.co/spaces/YOUR_USERNAME/crowdvision
cd crowdvision
# Copy required files
cp -r app/ weights/ app_gradio.py ./
cp requirements_hf.txt requirements.txt
cp README_HF.md README.md
# Push to deploy
git add .
git commit -m "Initial deployment"
git pushπ‘ Tip: HF Spaces offers free GPU for faster inference!
CrowdCounting/
βββ app/
β βββ main.py # FastAPI application
β βββ models/
β β βββ csrnet.py # CSRNet architecture
β β βββ p2pnet.py # P2PNet architecture
β βββ inference/
β β βββ density_inference.py # Density map inference
β β βββ localization_inference.py # Point detection inference
β βββ static/
β β βββ css/style.css
β β βββ js/main.js
β β βββ images/
β β βββ samples/ # Sample images for testing
β βββ templates/
β βββ index.html
βββ weights/
β βββ densitymap_model.pth # CSRNet weights (~65MB)
β βββ p2pnet_model.pth # P2PNet weights (~86MB)
βββ notebooks/ # Training notebooks
βββ app_gradio.py # Gradio app for HF Spaces
βββ requirements.txt # Fly.io dependencies
βββ requirements_hf.txt # HF Spaces dependencies
βββ Dockerfile # Docker configuration
βββ fly.toml # Fly.io configuration
- Architecture: VGG16 frontend + Dilated convolutional backend
- Output: Density map where sum of pixels = crowd count
- Best for: Large crowds, density distribution analysis
- Architecture: VGG16_bn backbone + FPN decoder + Regression/Classification heads
- Output: Point locations of detected heads
- Best for: Precise head counting, sparse to medium density crowds
- Parameters:
- Confidence Threshold: 0.4 (40%)
- NMS Distance: 8% of image diagonal
| Method | Endpoint | Description |
|---|---|---|
| GET | / |
Web interface |
| GET | /health |
Health check |
| POST | /predict/density |
Density map prediction |
| POST | /predict/localization |
Point detection prediction |
# Density Map
curl -X POST -F "file=@image.jpg" http://localhost:8000/predict/density
# Point Localization
curl -X POST -F "file=@image.jpg" "http://localhost:8000/predict/localization?threshold=0.4"{
"count": 25,
"method": "localization",
"visualization": "base64_encoded_image",
"points": [
{"x": 100.5, "y": 200.3, "confidence": 0.42}
],
"threshold": 0.4
}| Variable | Default | Description |
|---|---|---|
PORT |
8080 | Server port |
HOST |
0.0.0.0 | Server host |
- Lower threshold (0.3): More detections, more false positives
- Higher threshold (0.5): Fewer detections, more accurate
- Recommended: 0.4 for balanced results
The models were trained on custom crowd counting datasets. See the notebooks/ directory for:
densitymap.ipynb- CSRNet trainingp2pnet.ipynb- P2PNet training
- Image normalized with ImageNet mean/std
- P2PNet images resized to multiple of 128 pixels
- Point NMS applied to filter duplicate detections
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
