SakibRumu commited on
Commit
bfa5692
·
verified ·
1 Parent(s): cab70c8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -3
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 the custom class for safe loading
16
  torch.serialization.add_safe_globals({'YOLOv10DetectionModel': YOLOv10DetectionModel})
17
 
18
- # Load the model inside a safe context
19
  with torch.serialization.safe_globals({'YOLOv10DetectionModel': YOLOv10DetectionModel}):
20
- model = YOLO('/home/user/app/best.pt') # Load your YOLOv10 model
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)