Spaces:
Running
Running
onnx --> openvino, intel hardware
Browse files- 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 |
-
|
| 11 |
|
| 12 |
|
| 13 |
-
def
|
| 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
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
exported.rename(ONNX_PATH)
|
| 29 |
|
| 30 |
|
| 31 |
def load_model():
|
| 32 |
-
|
| 33 |
-
return YOLO(str(
|
|
|
|
| 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")
|