Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
CHANGED
|
@@ -71,17 +71,21 @@ def load_model():
|
|
| 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
|
|
|
|
| 75 |
custom_objects = {
|
| 76 |
-
'weighted_binary_crossentropy': weighted_binary_crossentropy
|
|
|
|
| 77 |
}
|
| 78 |
|
| 79 |
-
# Load the model using
|
|
|
|
| 80 |
# This is needed because the model was saved with tf_keras and a custom loss
|
| 81 |
-
model =
|
| 82 |
model_path,
|
| 83 |
compile=False,
|
| 84 |
-
custom_objects=custom_objects
|
|
|
|
| 85 |
)
|
| 86 |
print("Model loaded successfully!")
|
| 87 |
return model
|
|
|
|
| 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 custom loss function and TFRobertaModel
|
| 75 |
+
# TFRobertaModel is needed because the model architecture uses it
|
| 76 |
custom_objects = {
|
| 77 |
+
'weighted_binary_crossentropy': weighted_binary_crossentropy,
|
| 78 |
+
'TFRobertaModel': TFRobertaModel
|
| 79 |
}
|
| 80 |
|
| 81 |
+
# Load the model using tf_keras directly (not tf.keras) with custom_objects
|
| 82 |
+
# Use safe_mode=False to allow loading custom objects
|
| 83 |
# This is needed because the model was saved with tf_keras and a custom loss
|
| 84 |
+
model = tf_keras.models.load_model(
|
| 85 |
model_path,
|
| 86 |
compile=False,
|
| 87 |
+
custom_objects=custom_objects,
|
| 88 |
+
safe_mode=False
|
| 89 |
)
|
| 90 |
print("Model loaded successfully!")
|
| 91 |
return model
|