VietCat Amp commited on
Commit
679cf21
·
1 Parent(s): e1c596d

Add torch safe globals for model loading

Browse files

Amp-Thread-ID: https://ampcode.com/threads/T-22e83726-d77c-475f-b185-6d55f37c5979
Co-authored-by: Amp <amp@ampcode.com>

Files changed (1) hide show
  1. model.py +4 -1
model.py CHANGED
@@ -4,6 +4,7 @@ from ultralytics import YOLO
4
  import yaml
5
  from huggingface_hub import hf_hub_download
6
  import os
 
7
 
8
  class TrafficSignDetector:
9
  def __init__(self, config_path):
@@ -17,7 +18,9 @@ class TrafficSignDetector:
17
  repo_id = 'VietCat/GTSRB-Model'
18
  file_path = model_path.replace('VietCat/GTSRB-Model/', '')
19
  local_model_path = hf_hub_download(repo_id=repo_id, filename=file_path)
20
- self.model = YOLO(local_model_path)
 
 
21
  else:
22
  self.model = YOLO(model_path)
23
 
 
4
  import yaml
5
  from huggingface_hub import hf_hub_download
6
  import os
7
+ import torch
8
 
9
  class TrafficSignDetector:
10
  def __init__(self, config_path):
 
18
  repo_id = 'VietCat/GTSRB-Model'
19
  file_path = model_path.replace('VietCat/GTSRB-Model/', '')
20
  local_model_path = hf_hub_download(repo_id=repo_id, filename=file_path)
21
+ # Allow safe loading of ultralytics model
22
+ with torch.serialization.safe_globals([torch.nn.Module]):
23
+ self.model = YOLO(local_model_path)
24
  else:
25
  self.model = YOLO(model_path)
26