Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -38,7 +38,19 @@ class MultiAttributeClassifier:
|
|
| 38 |
model_path = f"models/classification/{category}_model.h5"
|
| 39 |
if os.path.exists(model_path):
|
| 40 |
print(f"π Loading model: {model_path}")
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
print(f"β
Loaded {category} model ({os.path.getsize(model_path)/1024/1024:.1f} MB)")
|
| 43 |
|
| 44 |
# Load encoder
|
|
@@ -132,7 +144,30 @@ class MultiAttributeClassifier:
|
|
| 132 |
try:
|
| 133 |
if os.path.exists(model_path):
|
| 134 |
print(f"π Trying to load: {model_path}")
|
| 135 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
print(f"β
Loaded GAN: {model_name} from {model_path}")
|
| 137 |
model_loaded = True
|
| 138 |
break
|
|
|
|
| 38 |
model_path = f"models/classification/{category}_model.h5"
|
| 39 |
if os.path.exists(model_path):
|
| 40 |
print(f"π Loading model: {model_path}")
|
| 41 |
+
try:
|
| 42 |
+
# Try normal loading first
|
| 43 |
+
self.models[category] = tf.keras.models.load_model(model_path)
|
| 44 |
+
except Exception as e1:
|
| 45 |
+
print(f" β οΈ Normal loading failed: {e1}")
|
| 46 |
+
try:
|
| 47 |
+
# Try with compile=False
|
| 48 |
+
self.models[category] = tf.keras.models.load_model(model_path, compile=False)
|
| 49 |
+
print(f" β
Loaded {category} with compile=False")
|
| 50 |
+
except Exception as e2:
|
| 51 |
+
print(f" β Failed to load {category}: {e2}")
|
| 52 |
+
continue
|
| 53 |
+
|
| 54 |
print(f"β
Loaded {category} model ({os.path.getsize(model_path)/1024/1024:.1f} MB)")
|
| 55 |
|
| 56 |
# Load encoder
|
|
|
|
| 144 |
try:
|
| 145 |
if os.path.exists(model_path):
|
| 146 |
print(f"π Trying to load: {model_path}")
|
| 147 |
+
# Try loading with different compatibility options
|
| 148 |
+
try:
|
| 149 |
+
# First try: Normal loading
|
| 150 |
+
self.gan_models[model_name] = tf.keras.models.load_model(model_path)
|
| 151 |
+
except Exception as e1:
|
| 152 |
+
print(f" β οΈ Normal loading failed: {e1}")
|
| 153 |
+
try:
|
| 154 |
+
# Second try: Load with compile=False (ignore training config)
|
| 155 |
+
self.gan_models[model_name] = tf.keras.models.load_model(model_path, compile=False)
|
| 156 |
+
print(f" β
Loaded with compile=False")
|
| 157 |
+
except Exception as e2:
|
| 158 |
+
print(f" β οΈ compile=False failed: {e2}")
|
| 159 |
+
try:
|
| 160 |
+
# Third try: Load with custom objects (for any custom layers)
|
| 161 |
+
self.gan_models[model_name] = tf.keras.models.load_model(
|
| 162 |
+
model_path,
|
| 163 |
+
compile=False,
|
| 164 |
+
custom_objects={'tf': tf}
|
| 165 |
+
)
|
| 166 |
+
print(f" β
Loaded with custom_objects")
|
| 167 |
+
except Exception as e3:
|
| 168 |
+
print(f" β All loading methods failed: {e3}")
|
| 169 |
+
raise e3
|
| 170 |
+
|
| 171 |
print(f"β
Loaded GAN: {model_name} from {model_path}")
|
| 172 |
model_loaded = True
|
| 173 |
break
|