mahmoudelsheemy commited on
Commit
e81f576
·
1 Parent(s): 5899fd9

Add debug info for model loading

Browse files
Files changed (1) hide show
  1. app.py +58 -19
app.py CHANGED
@@ -170,28 +170,59 @@ BINARY_MODEL = None
170
  DISEASE_MODEL = None
171
  TEETH_HEALTH_MODEL = None
172
 
 
 
 
 
 
 
173
  # Load binary model
174
- try:
175
- if os.path.exists(BINARY_MODEL_PATH):
176
- print(f"[INFO] Loading binary model from {BINARY_MODEL_PATH}...")
 
 
177
  BINARY_MODEL = tf.keras.models.load_model(BINARY_MODEL_PATH, compile=False)
178
- print("[SUCCESS] Binary model loaded")
179
- else:
180
- raise FileNotFoundError(f"Binary model not found")
181
- except Exception as e:
182
- print(f"[ERROR] Failed to load binary model: {e}")
 
 
 
 
 
 
 
 
 
 
 
183
  BINARY_MODEL = None
184
 
185
  # Load disease model
186
- try:
187
- if os.path.exists(DISEASE_MODEL_PATH):
188
- print(f"[INFO] Loading disease model from {DISEASE_MODEL_PATH}...")
 
189
  DISEASE_MODEL = tf.keras.models.load_model(DISEASE_MODEL_PATH, compile=False)
190
- print("[SUCCESS] Disease model loaded")
191
- else:
192
- raise FileNotFoundError(f"Disease model not found")
193
- except Exception as e:
194
- print(f"[ERROR] Failed to load disease model: {e}")
 
 
 
 
 
 
 
 
 
 
 
195
  DISEASE_MODEL = None
196
 
197
  # Load HuggingFace model
@@ -207,9 +238,17 @@ except Exception as e:
207
  print(f"[ERROR] Failed to load HuggingFace model: {e}")
208
  TEETH_HEALTH_MODEL = None
209
 
210
- # Verify models loaded
211
- if BINARY_MODEL is None or DISEASE_MODEL is None or TEETH_HEALTH_MODEL is None:
212
- print("\n[ERROR] One or more models failed to load. Exiting...")
 
 
 
 
 
 
 
 
213
  sys.exit(1)
214
 
215
  print("[INFO] All models loaded successfully\n")
 
170
  DISEASE_MODEL = None
171
  TEETH_HEALTH_MODEL = None
172
 
173
+ # Debug: Check if files exist
174
+ print(f"[DEBUG] Binary model exists: {os.path.exists(BINARY_MODEL_PATH)}")
175
+ print(f"[DEBUG] Binary model size: {os.path.getsize(BINARY_MODEL_PATH) if os.path.exists(BINARY_MODEL_PATH) else 0} bytes")
176
+ print(f"[DEBUG] Disease model exists: {os.path.exists(DISEASE_MODEL_PATH)}")
177
+ print(f"[DEBUG] Disease model size: {os.path.getsize(DISEASE_MODEL_PATH) if os.path.exists(DISEASE_MODEL_PATH) else 0} bytes")
178
+
179
  # Load binary model
180
+ if os.path.exists(BINARY_MODEL_PATH):
181
+ print(f"[INFO] Loading binary model from {BINARY_MODEL_PATH}...")
182
+ try:
183
+ # Try different loading methods
184
+ print("[INFO] Attempt 1: Loading with compile=False...")
185
  BINARY_MODEL = tf.keras.models.load_model(BINARY_MODEL_PATH, compile=False)
186
+ print("[SUCCESS] Binary model loaded successfully")
187
+ except Exception as e1:
188
+ print(f"[WARNING] Attempt 1 failed: {e1}")
189
+ try:
190
+ print("[INFO] Attempt 2: Loading with custom_objects...")
191
+ BINARY_MODEL = tf.keras.models.load_model(
192
+ BINARY_MODEL_PATH,
193
+ compile=False,
194
+ custom_objects={'InputLayer': tf.keras.layers.InputLayer}
195
+ )
196
+ print("[SUCCESS] Binary model loaded with custom_objects")
197
+ except Exception as e2:
198
+ print(f"[ERROR] Failed to load binary model: {e2}")
199
+ BINARY_MODEL = None
200
+ else:
201
+ print(f"[ERROR] Binary model not found at {BINARY_MODEL_PATH}")
202
  BINARY_MODEL = None
203
 
204
  # Load disease model
205
+ if os.path.exists(DISEASE_MODEL_PATH):
206
+ print(f"[INFO] Loading disease model from {DISEASE_MODEL_PATH}...")
207
+ try:
208
+ print("[INFO] Attempt 1: Loading with compile=False...")
209
  DISEASE_MODEL = tf.keras.models.load_model(DISEASE_MODEL_PATH, compile=False)
210
+ print("[SUCCESS] Disease model loaded successfully")
211
+ except Exception as e1:
212
+ print(f"[WARNING] Attempt 1 failed: {e1}")
213
+ try:
214
+ print("[INFO] Attempt 2: Loading with custom_objects...")
215
+ DISEASE_MODEL = tf.keras.models.load_model(
216
+ DISEASE_MODEL_PATH,
217
+ compile=False,
218
+ custom_objects={'InputLayer': tf.keras.layers.InputLayer}
219
+ )
220
+ print("[SUCCESS] Disease model loaded with custom_objects")
221
+ except Exception as e2:
222
+ print(f"[ERROR] Failed to load disease model: {e2}")
223
+ DISEASE_MODEL = None
224
+ else:
225
+ print(f"[ERROR] Disease model not found at {DISEASE_MODEL_PATH}")
226
  DISEASE_MODEL = None
227
 
228
  # Load HuggingFace model
 
238
  print(f"[ERROR] Failed to load HuggingFace model: {e}")
239
  TEETH_HEALTH_MODEL = None
240
 
241
+ # Final verification
242
+ print("\n[INFO] Final model status:")
243
+ print(f"Binary model: {'✅ LOADED' if BINARY_MODEL is not None else '❌ FAILED'}")
244
+ print(f"Disease model: {'✅ LOADED' if DISEASE_MODEL is not None else '❌ FAILED'}")
245
+ print(f"HuggingFace model: {'✅ LOADED' if TEETH_HEALTH_MODEL is not None else '❌ FAILED'}")
246
+
247
+ # Exit if critical models missing
248
+ if BINARY_MODEL is None or DISEASE_MODEL is None:
249
+ print("\n[ERROR] Critical TensorFlow models failed to load. Exiting...")
250
+ print("[ERROR] This is likely due to model compatibility issues.")
251
+ print("[ERROR] The models may need to be resaved with TensorFlow 2.12.")
252
  sys.exit(1)
253
 
254
  print("[INFO] All models loaded successfully\n")