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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -9
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 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
 
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