DawnC commited on
Commit
2aef774
·
verified ·
1 Parent(s): 32f3c60

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -1
app.py CHANGED
@@ -88,7 +88,22 @@ class ModelManager:
88
  'ConvNextV2Base_best_model.pth',
89
  map_location=self.device
90
  )
91
- self._breed_model.load_state_dict(checkpoint['base_model'], strict=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  self._breed_model.eval()
93
  return self._breed_model
94
 
 
88
  'ConvNextV2Base_best_model.pth',
89
  map_location=self.device
90
  )
91
+ if 'base_model' in checkpoint:
92
+
93
+ self._breed_model.load_state_dict(checkpoint['base_model'], strict=False)
94
+ elif 'model' in checkpoint:
95
+
96
+ self._breed_model.load_state_dict(checkpoint['model'], strict=False)
97
+ elif 'state_dict' in checkpoint:
98
+
99
+ self._breed_model.load_state_dict(checkpoint['state_dict'], strict=False)
100
+ else:
101
+
102
+ try:
103
+ self._breed_model.load_state_dict(checkpoint, strict=False)
104
+ except Exception as e:
105
+ print(f"嘗試載入模型權重時出錯: {e}")
106
+ print(f"checkpoint鍵: {list(checkpoint.keys()) if isinstance(checkpoint, dict) else 'Not a dictionary'}")
107
  self._breed_model.eval()
108
  return self._breed_model
109