SakibRumu
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -7,18 +7,26 @@ from PIL import Image
|
|
7 |
import sys
|
8 |
import os
|
9 |
|
|
|
10 |
import torch
|
11 |
import torch.serialization
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
from ultralytics import YOLO
|
13 |
from ultralytics.nn.tasks import YOLOv10DetectionModel
|
14 |
|
15 |
-
# Register
|
16 |
torch.serialization.add_safe_globals({'YOLOv10DetectionModel': YOLOv10DetectionModel})
|
17 |
|
18 |
-
# Load the model
|
19 |
with torch.serialization.safe_globals({'YOLOv10DetectionModel': YOLOv10DetectionModel}):
|
20 |
-
model = YOLO('/home/user/app/best.pt') #
|
21 |
|
|
|
22 |
# Frame processing function
|
23 |
def process_frame(frame):
|
24 |
img = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
|
|
7 |
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 repo to Python path
|
16 |
+
sys.path.append(str(Path(__file__).resolve().parent / "yolov10"))
|
17 |
+
|
18 |
+
# Now import YOLOv10 classes
|
19 |
from ultralytics import YOLO
|
20 |
from ultralytics.nn.tasks import YOLOv10DetectionModel
|
21 |
|
22 |
+
# Register YOLOv10DetectionModel to allow safe unpickling
|
23 |
torch.serialization.add_safe_globals({'YOLOv10DetectionModel': YOLOv10DetectionModel})
|
24 |
|
25 |
+
# Load the model safely
|
26 |
with torch.serialization.safe_globals({'YOLOv10DetectionModel': YOLOv10DetectionModel}):
|
27 |
+
model = YOLO('/home/user/app/best.pt') # Path to your trained YOLOv10n model
|
28 |
|
29 |
+
|
30 |
# Frame processing function
|
31 |
def process_frame(frame):
|
32 |
img = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|