Spaces:
Paused
Paused
Commit ·
ef2aeb3
1
Parent(s): 8806da0
fix: add CustomBatchNormalization to handle Keras 2 renorm kwargs on Keras 3
Browse files
app/services/prediction_service.py
CHANGED
|
@@ -55,6 +55,16 @@ class RandomShear(layers.Layer):
|
|
| 55 |
return config
|
| 56 |
|
| 57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
class MultiModelPredictor:
|
| 59 |
def __init__(self):
|
| 60 |
self.age_model = None
|
|
@@ -155,7 +165,10 @@ class MultiModelPredictor:
|
|
| 155 |
path = hf_hub_download(
|
| 156 |
repo_id=REPO_ID, filename=filename, token=settings.HF
|
| 157 |
)
|
| 158 |
-
return load_model(path, custom_objects={
|
|
|
|
|
|
|
|
|
|
| 159 |
|
| 160 |
self.age_model = get_model("age_finetuned_model_convnext.keras")
|
| 161 |
self.age_regression_model = get_model(
|
|
|
|
| 55 |
return config
|
| 56 |
|
| 57 |
|
| 58 |
+
class CustomBatchNormalization(layers.BatchNormalization):
|
| 59 |
+
"""Wrapper to strip Keras 2 'renorm' kwargs removed in Keras 3."""
|
| 60 |
+
|
| 61 |
+
def __init__(self, **kwargs):
|
| 62 |
+
kwargs.pop("renorm", None)
|
| 63 |
+
kwargs.pop("renorm_clipping", None)
|
| 64 |
+
kwargs.pop("renorm_momentum", None)
|
| 65 |
+
super().__init__(**kwargs)
|
| 66 |
+
|
| 67 |
+
|
| 68 |
class MultiModelPredictor:
|
| 69 |
def __init__(self):
|
| 70 |
self.age_model = None
|
|
|
|
| 165 |
path = hf_hub_download(
|
| 166 |
repo_id=REPO_ID, filename=filename, token=settings.HF
|
| 167 |
)
|
| 168 |
+
return load_model(path, custom_objects={
|
| 169 |
+
"RandomShear": RandomShear,
|
| 170 |
+
"BatchNormalization": CustomBatchNormalization,
|
| 171 |
+
})
|
| 172 |
|
| 173 |
self.age_model = get_model("age_finetuned_model_convnext.keras")
|
| 174 |
self.age_regression_model = get_model(
|