DawnC commited on
Commit
f4653e7
1 Parent(s): 78f7931

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -8
app.py CHANGED
@@ -593,8 +593,8 @@ class ModelManager:
593
  _initialized = False
594
 
595
  def __init__(self):
596
- self.model_yolo = None # YOLO模型
597
- self.model = None # 品種分類模型
598
 
599
  @classmethod
600
  async def get_instance(cls):
@@ -602,20 +602,14 @@ class ModelManager:
602
  cls._instance = cls()
603
  return cls._instance
604
 
605
- @spaces.GPU
606
  async def initialize(self):
607
- # 只初始化一次模型
608
  if not self._initialized:
609
- # 初始化 YOLO
610
  self.model_yolo = YOLO('yolov8l.pt')
611
-
612
- # 初始化品種分類模型
613
  num_classes = len(dog_breeds)
614
  self.model = BaseModel(num_classes=num_classes)
615
  checkpoint = torch.load('124_best_model_dog.pth')
616
  self.model.load_state_dict(checkpoint['base_model'], strict=False)
617
  self.model.eval()
618
-
619
  self._initialized = True
620
 
621
 
 
593
  _initialized = False
594
 
595
  def __init__(self):
596
+ self.model_yolo = None
597
+ self.model = None
598
 
599
  @classmethod
600
  async def get_instance(cls):
 
602
  cls._instance = cls()
603
  return cls._instance
604
 
 
605
  async def initialize(self):
 
606
  if not self._initialized:
 
607
  self.model_yolo = YOLO('yolov8l.pt')
 
 
608
  num_classes = len(dog_breeds)
609
  self.model = BaseModel(num_classes=num_classes)
610
  checkpoint = torch.load('124_best_model_dog.pth')
611
  self.model.load_state_dict(checkpoint['base_model'], strict=False)
612
  self.model.eval()
 
613
  self._initialized = True
614
 
615