YOLOv7 Window Detection with Measurements
A YOLOv7 model fine-tuned for detecting windows with dimensional measurements in architectural drawings.
Model Description
This model is a fine-tuned YOLOv7 object detector specialized for the window manufacturing industry. It automatically detects and locates windows with dimensional measurements in order documents, proposals, and technical drawings.
The model enables window manufacturers to:
- Automate order processing by detecting window boundaries in scanned or digital documents
- Extract individual window specifications from multi-window orders
- Support digital workflows for production planning and quoting
- Improve quality control by validating order completeness
Model Type: Object Detection (YOLOv7)
Industry: Window Manufacturing & Installation
Task: Window boundary detection in order documents and technical drawings
Classes: 1 (window)
Training Data
The model was trained on a custom dataset of architectural drawings containing:
- Training Images: 243 annotated images
- Validation Images: 61 annotated images
- Total Annotations: ~166 window instances
- Image Types: Scanned architectural drawings, floor plans, and technical construction documents
All images were manually annotated using labelImg with bounding boxes around windows. The dataset includes various drawing styles, scales, and quality levels to ensure robust detection.
Training Method
Base Model: YOLOv7 (pre-trained weights: yolov7_training.pt)
Training Approach: Transfer learning / Fine-tuning
Configuration:
- Epochs: 300
- Batch Size: 8
- Image Size: 640×640
- Device: CPU
- Optimizer: SGD with momentum
- Learning Rate: 0.01 (with cosine annealing)
Final Performance Metrics:
- Precision: 0.981
- Recall: 0.958
- mAP@0.5: 0.956
- mAP@0.5:0.95: 0.758
Intended Use
Primary Use Case
This model was specifically created for window manufacturers and their business partners to automate the processing of window orders and proposals. The model detects window boundaries with visible measurements in technical drawings and order documents, enabling:
- Automatic window boundary recognition in order documents and proposals
- Automated cropping and extraction of individual window specifications from multi-window drawings
- Perimeter and dimension calculations for manufacturing and quoting processes
- Quality control by verifying presence and completeness of window specifications
- Digital workflow automation for converting paper/PDF orders into structured data
Intended Users
- Window manufacturers (production planning, order processing)
- Window installation companies and contractors
- Manufacturing partners in the window supply chain
- Sales and quotation teams processing customer orders
- Quality assurance teams validating order specifications
Limitations
- Domain-specific: Optimized for architectural drawings; may not perform well on photographs or other image types
- Drawing quality: Performance may degrade on heavily degraded or low-quality scans
- Measurement accuracy: While the model detects windows with measurements, it does not extract or verify the numerical values
- Drawing styles: Best performance on technical/engineering drawings; artistic renderings may yield lower accuracy
- Language: Trained primarily on drawings with labels/text in specific language(s); may need adaptation for other languages
How to Use
Installation
1pip install torch torchvision
2git clone https://github.com/WongKinYiu/yolov7.git
3cd yolov7
Inference Code
1import torch
2from models.experimental import attempt_load
3from utils.general import non_max_suppression, scale_coords
4from utils.datasets import letterbox
5import cv2
6import numpy as np
7
8# Load model
9device = torch.device('cpu') # or 'cuda:0' for GPU
10model = attempt_load('window_with_measurements_best.pt', map_location=device)
11model.eval()
12
13# Prepare image
14img_path = 'your_drawing.jpg'
15img0 = cv2.imread(img_path)
16img = letterbox(img0, 640, stride=32)[0]
17img = img[:, :, ::-1].transpose(2, 0, 1) # BGR to RGB, to 3x640x640
18img = np.ascontiguousarray(img)
19img = torch.from_numpy(img).to(device)
20img = img.float() / 255.0
21if img.ndimension() == 3:
22 img = img.unsqueeze(0)
23
24# Inference
25with torch.no_grad():
26 pred = model(img)[0]
27 pred = non_max_suppression(pred, 0.25, 0.45)
28
29# Process detections
30for det in pred:
31 if len(det):
32 det[:, :4] = scale_coords(img.shape[2:], det[:, :4], img0.shape).round()
33 for *xyxy, conf, cls in det:
34 label = f'window {conf:.2f}'
35 print(f"Detected: {label} at {xyxy}")
36 # Draw bounding box
37 cv2.rectangle(img0, (int(xyxy[0]), int(xyxy[1])),
38 (int(xyxy[2]), int(xyxy[3])), (0, 255, 0), 2)
39 cv2.putText(img0, label, (int(xyxy[0]), int(xyxy[1])-10),
40 cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
41
42# Save result
43cv2.imwrite('result.jpg', img0)
Batch Processing for Window Orders
1import glob
2from pathlib import Path
3
4# Process multiple order documents
5order_paths = glob.glob('orders/*.jpg')
6for order_path in order_paths:
7 # Run inference (use code above)
8 # Save results to output directory
9 pass
Practical Example: Extract Windows for Manufacturing
1import os
2
3def extract_windows_from_order(image_path, output_dir):
4 """
5 Extract individual windows from an order document for processing.
6 Useful for separating windows for perimeter calculation, quoting, etc.
7 """
8 # Load and run inference (use inference code above)
9 img0 = cv2.imread(image_path)
10 # ... run detection ...
11
12 # Extract each detected window
13 for idx, (*xyxy, conf, cls) in enumerate(det):
14 # Crop window region
15 x1, y1, x2, y2 = map(int, xyxy)
16 window_crop = img0[y1:y2, x1:x2]
17
18 # Save individual window
19 window_filename = f"{Path(image_path).stem}_window_{idx+1}.jpg"
20 cv2.imwrite(os.path.join(output_dir, window_filename), window_crop)
21
22 # Optional: Calculate bounding box dimensions for perimeter
23 width_px = x2 - x1
24 height_px = y2 - y1
25 print(f"Window {idx+1}: {width_px}x{height_px} pixels")
26
27# Usage
28extract_windows_from_order('order_12345.jpg', 'extracted_windows/')
Training Details
Hardware: CPU (Mac)
Training Time: ~23.4 hours for 300 epochs
Framework: PyTorch 2.8.0
YOLOv7 Repository: WongKinYiu/yolov7
License
This model is released under the GPL-3.0 License (inherited from YOLOv7).
For commercial use, please review the YOLOv7 license terms and ensure compliance.
Citation
If you use this model in your research or project, please cite:
1@misc{yolov7-window-detection,
2 title={YOLOv7 Window Detection with Measurements},
3 author={Your Name},
4 year={2025},
5 howpublished={\url{https://huggingface.co/your-username/yolov7-window-detection}}
6}
And the original YOLOv7 paper:
1@article{wang2022yolov7,
2 title={{YOLOv7}: Trainable bag-of-freebies sets new state-of-the-art for real-time object detectors},
3 author={Wang, Chien-Yao and Bochkovskiy, Alexey and Liao, Hong-Yuan Mark},
4 journal={arXiv preprint arXiv:2207.02696},
5 year={2022}
6}
Contact
For questions, collaboration opportunities, or to learn more about our AI solutions for the window manufacturing industry, please visit our website or contact us through the channels listed there.
Acknowledgments
- YOLOv7 implementation by WongKinYiu
- Training infrastructure and annotation tools