xangcastle commited on
Commit
599f86e
·
1 Parent(s): ab952d9

activate cuda

Browse files
Files changed (1) hide show
  1. detector/utils.py +6 -3
detector/utils.py CHANGED
@@ -9,11 +9,14 @@ import requests
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
  def pad_img_to_fit_bbox(img, x1, x2, y1, y2):
19
  img = np.pad(img, ((np.abs(np.minimum(0, y1)), np.maximum(y2 - img.shape[0], 0)),
@@ -33,12 +36,12 @@ def imcrop(img, bbox):
33
 
34
 
35
  def detect_plates(img):
36
- return model_plates(img)
37
 
38
 
39
  def detect_chars(img):
40
  img = cv2.resize(img, (640, 320))
41
- detect = model_chars(img)
42
  records = detect.pandas().xyxy[0].to_dict(orient='records')
43
  text = ''
44
  if records:
 
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
+ device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
18
+ print('Loading models...', device)
19
+
20
 
21
  def pad_img_to_fit_bbox(img, x1, x2, y1, y2):
22
  img = np.pad(img, ((np.abs(np.minimum(0, y1)), np.maximum(y2 - img.shape[0], 0)),
 
36
 
37
 
38
  def detect_plates(img):
39
+ return model_plates(img, device=device)
40
 
41
 
42
  def detect_chars(img):
43
  img = cv2.resize(img, (640, 320))
44
+ detect = model_chars(img, device=device)
45
  records = detect.pandas().xyxy[0].to_dict(orient='records')
46
  text = ''
47
  if records: