SakibRumu
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -8,23 +8,23 @@ import sys
|
|
8 |
import os
|
9 |
|
10 |
import sys
|
11 |
-
import torch
|
12 |
-
import torch.serialization
|
13 |
from pathlib import Path
|
|
|
|
|
14 |
|
15 |
-
# Add yolov10
|
16 |
sys.path.append(str(Path(__file__).resolve().parent / "yolov10"))
|
17 |
|
18 |
-
# Now import
|
19 |
from ultralytics import YOLO
|
20 |
from ultralytics.nn.tasks import YOLOv10DetectionModel
|
21 |
|
22 |
-
# Register YOLOv10DetectionModel
|
23 |
-
|
24 |
|
25 |
-
# Load the model safely
|
26 |
-
with
|
27 |
-
model = YOLO('/home/user/app/best.pt') #
|
28 |
|
29 |
|
30 |
# Frame processing function
|
|
|
8 |
import os
|
9 |
|
10 |
import sys
|
|
|
|
|
11 |
from pathlib import Path
|
12 |
+
import torch
|
13 |
+
from torch.serialization import add_safe_globals, safe_globals
|
14 |
|
15 |
+
# Add yolov10 directory to Python path
|
16 |
sys.path.append(str(Path(__file__).resolve().parent / "yolov10"))
|
17 |
|
18 |
+
# Now import from yolov10
|
19 |
from ultralytics import YOLO
|
20 |
from ultralytics.nn.tasks import YOLOv10DetectionModel
|
21 |
|
22 |
+
# Register the actual YOLOv10DetectionModel class for safe loading
|
23 |
+
add_safe_globals([YOLOv10DetectionModel])
|
24 |
|
25 |
+
# Load the model safely using context manager
|
26 |
+
with safe_globals([YOLOv10DetectionModel]):
|
27 |
+
model = YOLO('/home/user/app/best.pt') # Make sure this file exists
|
28 |
|
29 |
|
30 |
# Frame processing function
|