Meshyboi commited on
Commit
53f5e59
·
verified ·
1 Parent(s): 1c30d32

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -3
app.py CHANGED
@@ -61,9 +61,28 @@ def load_model():
61
  cache_dir=None # Use default cache
62
  )
63
  print(f"Model downloaded to: {model_path}")
64
- # Load the model using TensorFlow's Keras (not standalone Keras)
65
- # This is needed because the model was saved with tf_keras
66
- model = tf.keras.models.load_model(model_path, compile=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  print("Model loaded successfully!")
68
  return model
69
  except Exception as e:
 
61
  cache_dir=None # Use default cache
62
  )
63
  print(f"Model downloaded to: {model_path}")
64
+
65
+ # Define a dummy weighted_binary_crossentropy function for loading
66
+ # (not used during inference since compile=False)
67
+ def weighted_binary_crossentropy(y_true, y_pred):
68
+ # Dummy implementation - not used during inference
69
+ epsilon = tf.keras.backend.epsilon()
70
+ y_pred = tf.clip_by_value(y_pred, epsilon, 1.0 - epsilon)
71
+ bce = -(y_true * tf.math.log(y_pred) + (1.0 - y_true) * tf.math.log(1.0 - y_pred))
72
+ return tf.reduce_mean(bce)
73
+
74
+ # Provide custom_objects to handle the custom loss function
75
+ custom_objects = {
76
+ 'weighted_binary_crossentropy': weighted_binary_crossentropy
77
+ }
78
+
79
+ # Load the model using TensorFlow's Keras with custom_objects
80
+ # This is needed because the model was saved with tf_keras and a custom loss
81
+ model = tf.keras.models.load_model(
82
+ model_path,
83
+ compile=False,
84
+ custom_objects=custom_objects
85
+ )
86
  print("Model loaded successfully!")
87
  return model
88
  except Exception as e: