EngReem85 commited on
Commit
02e4199
·
verified ·
1 Parent(s): c33d423

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -5
app.py CHANGED
@@ -98,7 +98,7 @@ class DFUTissueSegNet(nn.Module):
98
  # تحميل النموذج
99
  # ======================================================
100
  def initialize_model():
101
- """تحميل DFUTissueSegNet من Google Drive"""
102
  global segmenter
103
  MODEL_URL = "https://drive.google.com/uc?id=1Ovaczsjdp3E-_gYF2pbUibDjPWAC1a6c"
104
  MODEL_PATH = "best_model_5.pth"
@@ -108,18 +108,34 @@ def initialize_model():
108
  gdown.download(MODEL_URL, MODEL_PATH, quiet=False)
109
 
110
  try:
111
- print("🔄 تحميل النموذج...")
112
  segmenter = DFUTissueSegNet(num_classes=3)
113
- state_dict = torch.load(MODEL_PATH, map_location=DEVICE)
114
- segmenter.load_state_dict(state_dict)
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  segmenter.to(DEVICE)
116
  segmenter.eval()
117
  print("✅ تم تحميل DFUTissueSegNet من Google Drive بنجاح.")
118
  except Exception as e:
119
- print(f"❌ خطأ في تحميل النموذج: {e}")
 
 
120
  segmenter = None
121
 
122
 
 
123
  # ======================================================
124
  # دالة التجزئة
125
  # ======================================================
 
98
  # تحميل النموذج
99
  # ======================================================
100
  def initialize_model():
101
+ """تحميل DFUTissueSegNet من Google Drive مع دعم checkpoint الكامل"""
102
  global segmenter
103
  MODEL_URL = "https://drive.google.com/uc?id=1Ovaczsjdp3E-_gYF2pbUibDjPWAC1a6c"
104
  MODEL_PATH = "best_model_5.pth"
 
108
  gdown.download(MODEL_URL, MODEL_PATH, quiet=False)
109
 
110
  try:
111
+ print("🔄 تحميل DFUTissueSegNet...")
112
  segmenter = DFUTissueSegNet(num_classes=3)
113
+ checkpoint = torch.load(MODEL_PATH, map_location=DEVICE)
114
+
115
+ # بعض النماذج تكون محفوظة داخل "state_dict"
116
+ if "state_dict" in checkpoint:
117
+ state_dict = checkpoint["state_dict"]
118
+ else:
119
+ state_dict = checkpoint
120
+
121
+ # إزالة البادئة "model." أو "module." لو وجدت
122
+ clean_state = {}
123
+ for k, v in state_dict.items():
124
+ nk = k.replace("module.", "").replace("model.", "")
125
+ clean_state[nk] = v
126
+
127
+ segmenter.load_state_dict(clean_state, strict=False)
128
  segmenter.to(DEVICE)
129
  segmenter.eval()
130
  print("✅ تم تحميل DFUTissueSegNet من Google Drive بنجاح.")
131
  except Exception as e:
132
+ print(f"❌ فشل تحميل النموذج: {e}")
133
+ import traceback
134
+ traceback.print_exc()
135
  segmenter = None
136
 
137
 
138
+
139
  # ======================================================
140
  # دالة التجزئة
141
  # ======================================================