Subh775 commited on
Commit
7326db3
·
1 Parent(s): 688c241

onnx --> openvino, intel hardware

Browse files
Files changed (1) hide show
  1. backend/model.py +9 -9
backend/model.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import os
2
  from pathlib import Path
3
  from dotenv import load_dotenv
@@ -7,10 +8,10 @@ load_dotenv()
7
 
8
  MODEL_DIR = Path(__file__).parent / "weights"
9
  PT_PATH = MODEL_DIR / "best.pt"
10
- ONNX_PATH = MODEL_DIR / "best.onnx"
11
 
12
 
13
- def ensure_onnx():
14
  MODEL_DIR.mkdir(exist_ok=True)
15
 
16
  if not PT_PATH.exists():
@@ -21,13 +22,12 @@ def ensure_onnx():
21
  f'https://huggingface.co/Perception365/VehicleNet-Y26s/resolve/main/weights/best.pt'
22
  )
23
 
24
- if not ONNX_PATH.exists():
25
- YOLO(str(PT_PATH)).export(format="onnx", dynamic=True)
26
- exported = PT_PATH.with_suffix(".onnx")
27
- if exported != ONNX_PATH:
28
- exported.rename(ONNX_PATH)
29
 
30
 
31
  def load_model():
32
- ensure_onnx()
33
- return YOLO(str(ONNX_PATH), task="detect")
 
1
+ # Using OpenVino as per Space settings compatible for performance on Intel CPU hardware
2
  import os
3
  from pathlib import Path
4
  from dotenv import load_dotenv
 
8
 
9
  MODEL_DIR = Path(__file__).parent / "weights"
10
  PT_PATH = MODEL_DIR / "best.pt"
11
+ OV_PATH = MODEL_DIR / "best_openvino_model" # it's a directory
12
 
13
 
14
+ def ensure_openvino():
15
  MODEL_DIR.mkdir(exist_ok=True)
16
 
17
  if not PT_PATH.exists():
 
22
  f'https://huggingface.co/Perception365/VehicleNet-Y26s/resolve/main/weights/best.pt'
23
  )
24
 
25
+ if not OV_PATH.exists():
26
+ # Export happens relative to the .pt file's location
27
+ # Result will be: weights/best_openvino_model/
28
+ YOLO(str(PT_PATH)).export(format="openvino", dynamic=True)
 
29
 
30
 
31
  def load_model():
32
+ ensure_openvino()
33
+ return YOLO(str(OV_PATH), task="detect")