koesan commited on
Commit
df14132
·
verified ·
1 Parent(s): 6e88fef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -12
app.py CHANGED
@@ -24,22 +24,20 @@ os.environ['TF_FORCE_GPU_ALLOW_GROWTH'] = 'true'
24
  # Try loading with h5py directly for better compatibility
25
  import h5py
26
 
 
27
  try:
28
- # Use legacy loader which is more compatible
29
- from tensorflow.keras.saving import legacy
30
- model = legacy.load_model.load_model('cancer_model.h5', compile=False)
31
- print("Model loaded successfully with legacy loader!")
32
  except Exception as e:
33
- print(f"Legacy loader failed: {e}")
34
  try:
35
- # Fallback: try standard loader
36
- model = load_model('cancer_model.h5', compile=False)
37
- print("Model loaded successfully!")
38
  except Exception as e2:
39
- print(f"Standard loader also failed: {e2}")
40
- print("\nPlease re-save your model using:")
41
- print(" model.save('cancer_model.h5', save_format='h5')")
42
- print("Or convert to SavedModel format for better compatibility")
43
  raise
44
 
45
  def resize_with_padding(img, target_size):
 
24
  # Try loading with h5py directly for better compatibility
25
  import h5py
26
 
27
+ # Load model with old TensorFlow/Keras compatibility
28
  try:
29
+ # Direct loading with old Keras
30
+ from keras.models import load_model as keras_load_model
31
+ model = keras_load_model('cancer_model.h5', compile=False)
32
+ print("Model loaded successfully with Keras 2.4.3!")
33
  except Exception as e:
34
+ print(f"Keras loader failed: {e}")
35
  try:
36
+ # Try TensorFlow loader
37
+ model = tf.keras.models.load_model('cancer_model.h5', compile=False)
38
+ print("Model loaded successfully with TensorFlow!")
39
  except Exception as e2:
40
+ print(f"Error: {e2}")
 
 
 
41
  raise
42
 
43
  def resize_with_padding(img, target_size):