Update README.md
Browse files
README.md
CHANGED
|
@@ -5,6 +5,375 @@ colorFrom: pink
|
|
| 5 |
colorTo: indigo
|
| 6 |
sdk: docker
|
| 7 |
pinned: false
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
colorTo: indigo
|
| 6 |
sdk: docker
|
| 7 |
pinned: false
|
| 8 |
+
license: mit
|
| 9 |
---
|
| 10 |
|
| 11 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
| 12 |
+
|
| 13 |
+
# Door & Window Detection using YOLOv8
|
| 14 |
+
|
| 15 |
+
A custom-trained YOLOv8 model for detecting doors and windows in construction blueprint-style images, deployed as a FastAPI service with dual response modes.
|
| 16 |
+
|
| 17 |
+
## π Demo
|
| 18 |
+
|
| 19 |
+
**Live API**: [https://huggingface.co/spaces/kurakula-Prashanth2004/door-window-detection](https://huggingface.co/spaces/kurakula-Prashanth2004/door-window-detection)
|
| 20 |
+
|
| 21 |
+
**GitHub Repository**: [https://github.com/kurakula-prashanth/door-window-detection](https://github.com/kurakula-prashanth/door-window-detection)
|
| 22 |
+
|
| 23 |
+
## π Project Overview
|
| 24 |
+
|
| 25 |
+
This project implements a complete machine learning pipeline for detecting doors and windows in architectural blueprints:
|
| 26 |
+
|
| 27 |
+
1. **Manual Data Labeling** - Created custom dataset with bounding box annotations
|
| 28 |
+
2. **Model Training** - Trained YOLOv8 model from scratch using only custom-labeled data
|
| 29 |
+
3. **API Development** - Built FastAPI service with dual response modes (JSON + annotated images)
|
| 30 |
+
4. **Deployment** - Deployed to Hugging Face Spaces with Docker
|
| 31 |
+
|
| 32 |
+
## π― Classes Detected
|
| 33 |
+
|
| 34 |
+
- `door` - Door symbols in blueprints
|
| 35 |
+
- `window` - Window symbols in blueprints
|
| 36 |
+
|
| 37 |
+
## β¨ Key Features
|
| 38 |
+
|
| 39 |
+
- **Dual Response Modes**: Get JSON data or annotated images
|
| 40 |
+
- **Interactive Swagger UI**: Built-in API documentation at `/docs`
|
| 41 |
+
- **Smart Image Processing**: Automatic resizing for large images (max 1280px)
|
| 42 |
+
- **GPU Acceleration**: CUDA support with FP16 precision
|
| 43 |
+
- **Async Processing**: Non-blocking inference with ThreadPoolExecutor
|
| 44 |
+
- **Dynamic Color Coding**: Consistent colors for each detection class
|
| 45 |
+
- **Confidence Filtering**: Configurable confidence thresholds (default: 0.5)
|
| 46 |
+
|
| 47 |
+
## π οΈ Setup & Installation
|
| 48 |
+
|
| 49 |
+
### Local Development
|
| 50 |
+
|
| 51 |
+
1. **Clone the repository**
|
| 52 |
+
```bash
|
| 53 |
+
git clone https://github.com/kurakula-prashanth/door-window-detection.git
|
| 54 |
+
cd door-window-detection
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
2. **Create virtual environment**
|
| 58 |
+
```bash
|
| 59 |
+
python3.12 -m venv yolo8_custom
|
| 60 |
+
source yolo8_custom/bin/activate # On Windows: yolo8_custom\Scripts\activate
|
| 61 |
+
```
|
| 62 |
+
|
| 63 |
+
3. **Install dependencies**
|
| 64 |
+
```bash
|
| 65 |
+
pip install -r requirements.txt
|
| 66 |
+
```
|
| 67 |
+
|
| 68 |
+
4. **Run the API locally**
|
| 69 |
+
```bash
|
| 70 |
+
uvicorn app:app --host 0.0.0.0 --port 8000 --reload
|
| 71 |
+
```
|
| 72 |
+
|
| 73 |
+
5. **Access the API**
|
| 74 |
+
- **Interactive Documentation**: http://localhost:8000/docs
|
| 75 |
+
- **API Endpoint**: http://localhost:8000/predict
|
| 76 |
+
|
| 77 |
+
## π Training Process
|
| 78 |
+
|
| 79 |
+
### Step 1: Data Labeling
|
| 80 |
+
- Used **LabelImg** for manual annotation
|
| 81 |
+
- Labeled 15-20 construction blueprint images
|
| 82 |
+
- Created bounding boxes for doors and windows only
|
| 83 |
+
- Generated YOLO format labels (.txt files)
|
| 84 |
+
|
| 85 |
+

|
| 86 |
+
|
| 87 |
+

|
| 88 |
+
|
| 89 |
+

|
| 90 |
+
|
| 91 |
+

|
| 92 |
+
|
| 93 |
+
### Step 2: Model Training
|
| 94 |
+
```bash
|
| 95 |
+
yolo task=detect mode=train epochs=100 data=data_custom.yaml model=yolov8m.pt imgsz=640
|
| 96 |
+
```
|
| 97 |
+
**Training Configuration:**
|
| 98 |
+
- Base Model: YOLOv8 Medium (yolov8m.pt)
|
| 99 |
+
- Epochs: 100
|
| 100 |
+
- Image Size: 640x640
|
| 101 |
+
- Classes: 2 (door, window)
|
| 102 |
+
|
| 103 |
+

|
| 104 |
+
|
| 105 |
+

|
| 106 |
+
|
| 107 |
+

|
| 108 |
+
|
| 109 |
+

|
| 110 |
+
|
| 111 |
+
### Step 3: Model Testing
|
| 112 |
+
```bash
|
| 113 |
+
yolo task=detect mode=predict model=best.pt show=true conf=0.5 source=12.png line_thickness=1
|
| 114 |
+
```
|
| 115 |
+

|
| 116 |
+
|
| 117 |
+

|
| 118 |
+
|
| 119 |
+
## π API Usage
|
| 120 |
+
|
| 121 |
+
### Main Endpoint
|
| 122 |
+
```
|
| 123 |
+
POST /predict
|
| 124 |
+
```
|
| 125 |
+
|
| 126 |
+
### Parameters
|
| 127 |
+
- **file** (required): Upload PNG or JPG image (max 10MB)
|
| 128 |
+
- **response_type** (required): Choose between `json` or `image`
|
| 129 |
+
|
| 130 |
+
### Response Modes
|
| 131 |
+
|
| 132 |
+
#### 1. JSON Response (`response_type=json`)
|
| 133 |
+
Returns detection data in JSON format:
|
| 134 |
+
|
| 135 |
+
```json
|
| 136 |
+
{
|
| 137 |
+
"detections": [
|
| 138 |
+
{
|
| 139 |
+
"label": "door",
|
| 140 |
+
"confidence": 0.91,
|
| 141 |
+
"bbox": [x, y, width, height]
|
| 142 |
+
},
|
| 143 |
+
{
|
| 144 |
+
"label": "window",
|
| 145 |
+
"confidence": 0.84,
|
| 146 |
+
"bbox": [x, y, width, height]
|
| 147 |
+
}
|
| 148 |
+
]
|
| 149 |
+
}
|
| 150 |
+
```
|
| 151 |
+
|
| 152 |
+
#### 2. Image Response (`response_type=image`)
|
| 153 |
+
Returns annotated PNG image with:
|
| 154 |
+
- Bounding boxes around detected objects
|
| 155 |
+
- Labels with confidence scores
|
| 156 |
+
- Color-coded detection classes
|
| 157 |
+
- Detection count in response headers
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+

|
| 161 |
+
|
| 162 |
+

|
| 163 |
+
|
| 164 |
+

|
| 165 |
+
|
| 166 |
+
### Usage Examples
|
| 167 |
+
|
| 168 |
+
#### cURL - JSON Response
|
| 169 |
+
```bash
|
| 170 |
+
curl -X POST "https://huggingface.co/spaces/kurakula-Prashanth2004/door-window-detection/predict" \
|
| 171 |
+
-F "file=@your_blueprint.png" \
|
| 172 |
+
-F "response_type=json"
|
| 173 |
+
```
|
| 174 |
+
|
| 175 |
+
#### cURL - Image Response
|
| 176 |
+
```bash
|
| 177 |
+
curl -X POST "https://huggingface.co/spaces/kurakula-Prashanth2004/door-window-detection/predict" \
|
| 178 |
+
-F "file=@your_blueprint.png" \
|
| 179 |
+
-F "response_type=image" \
|
| 180 |
+
--output detected_result.png
|
| 181 |
+
```
|
| 182 |
+
|
| 183 |
+
#### Python - JSON Response
|
| 184 |
+
```python
|
| 185 |
+
import requests
|
| 186 |
+
|
| 187 |
+
url = "https://huggingface.co/spaces/kurakula-Prashanth2004/door-window-detection/predict"
|
| 188 |
+
files = {"file": open("blueprint.png", "rb")}
|
| 189 |
+
data = {"response_type": "json"}
|
| 190 |
+
|
| 191 |
+
response = requests.post(url, files=files, data=data)
|
| 192 |
+
detections = response.json()["detections"]
|
| 193 |
+
print(f"Found {len(detections)} objects")
|
| 194 |
+
```
|
| 195 |
+
|
| 196 |
+
#### Python - Image Response
|
| 197 |
+
```python
|
| 198 |
+
import requests
|
| 199 |
+
|
| 200 |
+
url = "https://huggingface.co/spaces/kurakula-Prashanth2004/door-window-detection/predict"
|
| 201 |
+
files = {"file": open("blueprint.png", "rb")}
|
| 202 |
+
data = {"response_type": "image"}
|
| 203 |
+
|
| 204 |
+
response = requests.post(url, files=files, data=data)
|
| 205 |
+
with open("annotated_result.png", "wb") as f:
|
| 206 |
+
f.write(response.content)
|
| 207 |
+
```
|
| 208 |
+
|
| 209 |
+
## π³ Docker Deployment
|
| 210 |
+
|
| 211 |
+
The application is containerized using Docker:
|
| 212 |
+
|
| 213 |
+
```dockerfile
|
| 214 |
+
FROM python:3.10-slim
|
| 215 |
+
|
| 216 |
+
ENV PYTHONDONTWRITEBYTECODE=1
|
| 217 |
+
ENV PYTHONUNBUFFERED=1
|
| 218 |
+
|
| 219 |
+
WORKDIR /app
|
| 220 |
+
|
| 221 |
+
# Install system dependencies
|
| 222 |
+
RUN apt-get update && apt-get install -y \
|
| 223 |
+
libglib2.0-0 libgl1-mesa-glx \
|
| 224 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 225 |
+
|
| 226 |
+
# Install Python dependencies
|
| 227 |
+
COPY requirements.txt .
|
| 228 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 229 |
+
|
| 230 |
+
COPY . .
|
| 231 |
+
|
| 232 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
| 233 |
+
```
|
| 234 |
+
|
| 235 |
+
## π¦ Dependencies
|
| 236 |
+
|
| 237 |
+
```txt
|
| 238 |
+
fastapi
|
| 239 |
+
uvicorn
|
| 240 |
+
ultralytics
|
| 241 |
+
opencv-python-headless
|
| 242 |
+
pillow
|
| 243 |
+
torch
|
| 244 |
+
numpy
|
| 245 |
+
python-multipart
|
| 246 |
+
```
|
| 247 |
+
|
| 248 |
+
## β‘ Performance Features
|
| 249 |
+
|
| 250 |
+
- **GPU Acceleration**: Automatically uses CUDA if available with FP16 precision
|
| 251 |
+
- **Model Warmup**: Dummy inference on startup for faster first request
|
| 252 |
+
- **Async Processing**: Non-blocking image processing with ThreadPoolExecutor (2 workers)
|
| 253 |
+
- **Smart Resizing**: Large images automatically resized to max 1280px
|
| 254 |
+
- **Memory Efficient**: Optimized for production deployment
|
| 255 |
+
- **Confidence Thresholding**: Filters low-confidence detections (β₯0.5)
|
| 256 |
+
- **IoU Filtering**: Non-maximum suppression with 0.45 threshold
|
| 257 |
+
- **Color Consistency**: Hash-based color generation for detection labels
|
| 258 |
+
|
| 259 |
+
## π Project Structure
|
| 260 |
+
|
| 261 |
+
```
|
| 262 |
+
door-window-detection/
|
| 263 |
+
βββ app.py # FastAPI application
|
| 264 |
+
βββ requirements.txt # Python dependencies
|
| 265 |
+
βββ Dockerfile # Container configuration
|
| 266 |
+
βββ yolov8m_custom.pt # Trained model weights
|
| 267 |
+
βββ data_custom.yaml # Training configuration
|
| 268 |
+
βββ classes.txt # Class names
|
| 269 |
+
βββ datasets/ # Training data
|
| 270 |
+
β βββ images/
|
| 271 |
+
β βββ labels/
|
| 272 |
+
βββ README.md # This file
|
| 273 |
+
```
|
| 274 |
+
|
| 275 |
+
## π Model Configuration
|
| 276 |
+
|
| 277 |
+
- **Architecture**: YOLOv8 Medium (yolov8m_custom.pt)
|
| 278 |
+
- **Input Processing**: Auto-resize to max 1280px, maintains aspect ratio
|
| 279 |
+
- **Inference Settings**:
|
| 280 |
+
- Confidence Threshold: 0.5
|
| 281 |
+
- IoU Threshold: 0.45
|
| 282 |
+
- Max Detections: 100
|
| 283 |
+
- Half Precision: Enabled on GPU
|
| 284 |
+
- **Classes**: 2 (door, window)
|
| 285 |
+
- **Training Data**: Custom-labeled blueprint images
|
| 286 |
+
|
| 287 |
+
## π¨ Visual Features
|
| 288 |
+
|
| 289 |
+
- **Dynamic Bounding Boxes**: Color-coded by detection class
|
| 290 |
+
- **Confidence Labels**: Shows class name and confidence score
|
| 291 |
+
- **Hash-based Colors**: Consistent colors for each label type
|
| 292 |
+
- **High-Quality Output**: PNG format with preserved image quality
|
| 293 |
+
|
| 294 |
+
## π§ API Configuration
|
| 295 |
+
|
| 296 |
+
- **File Size Limit**: 10MB maximum
|
| 297 |
+
- **Supported Formats**: JPG, PNG
|
| 298 |
+
- **Concurrent Processing**: 2 worker threads
|
| 299 |
+
- **Response Headers**: Include detection count metadata
|
| 300 |
+
- **Error Handling**: Comprehensive validation and error messages
|
| 301 |
+
|
| 302 |
+
## π Results & Screenshots
|
| 303 |
+
|
| 304 |
+
### Training Progress
|
| 305 |
+
- Loss curves and training metrics
|
| 306 |
+
- Model performance on validation set
|
| 307 |
+
- Convergence after 100 epochs
|
| 308 |
+
|
| 309 |
+
#### Confusion Matrix
|
| 310 |
+
|
| 311 |
+

|
| 312 |
+
|
| 313 |
+
#### Confusion Matrix Normalized
|
| 314 |
+
|
| 315 |
+

|
| 316 |
+
|
| 317 |
+
#### Confusion F1 Curve
|
| 318 |
+
|
| 319 |
+

|
| 320 |
+
|
| 321 |
+
#### labels
|
| 322 |
+
|
| 323 |
+

|
| 324 |
+
|
| 325 |
+
#### P_curve
|
| 326 |
+
|
| 327 |
+

|
| 328 |
+
|
| 329 |
+
#### PR_Curve
|
| 330 |
+
|
| 331 |
+

|
| 332 |
+
|
| 333 |
+
#### R Curve
|
| 334 |
+
|
| 335 |
+

|
| 336 |
+
|
| 337 |
+
#### Results
|
| 338 |
+
|
| 339 |
+

|
| 340 |
+
|
| 341 |
+
### API Responses
|
| 342 |
+
|
| 343 |
+
- JSON detection data examples
|
| 344 |
+
|
| 345 |
+

|
| 346 |
+
|
| 347 |
+
|
| 348 |
+
- Annotated image outputs
|
| 349 |
+
|
| 350 |
+

|
| 351 |
+
|
| 352 |
+
- Performance benchmarks
|
| 353 |
+
|
| 354 |
+
### Interactive Documentation
|
| 355 |
+
- Swagger UI at `/docs`
|
| 356 |
+
- Parameter descriptions
|
| 357 |
+
- Live API testing interface
|
| 358 |
+
|
| 359 |
+

|
| 360 |
+
|
| 361 |
+
|
| 362 |
+
## π€ Contributing
|
| 363 |
+
|
| 364 |
+
1. Fork the repository
|
| 365 |
+
2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
|
| 366 |
+
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
|
| 367 |
+
4. Push to the branch (`git push origin feature/AmazingFeature`)
|
| 368 |
+
5. Open a Pull Request
|
| 369 |
+
|
| 370 |
+
## π License
|
| 371 |
+
|
| 372 |
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
| 373 |
+
|
| 374 |
+
## π Acknowledgments
|
| 375 |
+
|
| 376 |
+
- YOLOv8 by Ultralytics
|
| 377 |
+
- FastAPI framework
|
| 378 |
+
- Hugging Face Spaces for deployment
|
| 379 |
+
- LabelImg for annotation tool
|