Views
No views yet
windows-frames2 dataset runyolov7_training.pt)1pip install torch torchvision
2git clone https://github.com/WongKinYiu/yolov7.git
3cd yolov71import 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('windows_without_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 cv2.rectangle(img0, (int(xyxy[0]), int(xyxy[1])),
37 (int(xyxy[2]), int(xyxy[3])), (0, 255, 0), 2)