Spaces:
Runtime error
Runtime error
Commit
·
f8c5956
1
Parent(s):
599f86e
activate cuda
Browse files- detector/utils.py +9 -5
detector/utils.py
CHANGED
@@ -8,14 +8,18 @@ import requests
|
|
8 |
|
9 |
BASE_DIR = os.path.abspath(os.getcwd())
|
10 |
|
|
|
|
|
|
|
11 |
model_plates = torch.hub.load('ultralytics/yolov5', 'custom',
|
12 |
-
path=os.path.join(BASE_DIR, 'detector', 'static', 'plates.pt')
|
|
|
|
|
13 |
|
14 |
model_chars = torch.hub.load('ultralytics/yolov5', 'custom',
|
15 |
path=os.path.join(BASE_DIR, 'detector', 'static', 'chars.pt'))
|
16 |
|
17 |
-
|
18 |
-
print('Loading models...', device)
|
19 |
|
20 |
|
21 |
def pad_img_to_fit_bbox(img, x1, x2, y1, y2):
|
@@ -36,12 +40,12 @@ def imcrop(img, bbox):
|
|
36 |
|
37 |
|
38 |
def detect_plates(img):
|
39 |
-
return model_plates(img
|
40 |
|
41 |
|
42 |
def detect_chars(img):
|
43 |
img = cv2.resize(img, (640, 320))
|
44 |
-
detect = model_chars(img
|
45 |
records = detect.pandas().xyxy[0].to_dict(orient='records')
|
46 |
text = ''
|
47 |
if records:
|
|
|
8 |
|
9 |
BASE_DIR = os.path.abspath(os.getcwd())
|
10 |
|
11 |
+
device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
|
12 |
+
print('Loading models...', device)
|
13 |
+
|
14 |
model_plates = torch.hub.load('ultralytics/yolov5', 'custom',
|
15 |
+
path=os.path.join(BASE_DIR, 'detector', 'static', 'plates.pt'))
|
16 |
+
|
17 |
+
model_plates.to(device).eval()
|
18 |
|
19 |
model_chars = torch.hub.load('ultralytics/yolov5', 'custom',
|
20 |
path=os.path.join(BASE_DIR, 'detector', 'static', 'chars.pt'))
|
21 |
|
22 |
+
model_chars.to(device).eval()
|
|
|
23 |
|
24 |
|
25 |
def pad_img_to_fit_bbox(img, x1, x2, y1, y2):
|
|
|
40 |
|
41 |
|
42 |
def detect_plates(img):
|
43 |
+
return model_plates(img)
|
44 |
|
45 |
|
46 |
def detect_chars(img):
|
47 |
img = cv2.resize(img, (640, 320))
|
48 |
+
detect = model_chars(img)
|
49 |
records = detect.pandas().xyxy[0].to_dict(orient='records')
|
50 |
text = ''
|
51 |
if records:
|