Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,8 +6,23 @@ import numpy as np
|
|
| 6 |
import tensorflow as tf
|
| 7 |
from PIL import Image
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
labels = ["Cardboard", "Glass", "Metal", "Paper", "Plastic", "Trash"]
|
| 13 |
|
|
|
|
| 6 |
import tensorflow as tf
|
| 7 |
from PIL import Image
|
| 8 |
|
| 9 |
+
# ✅ Custom fix for batch_shape compatibility
|
| 10 |
+
from tensorflow.keras.layers import InputLayer
|
| 11 |
+
|
| 12 |
+
class CompatibleInputLayer(InputLayer):
|
| 13 |
+
def __init__(self, *args, **kwargs):
|
| 14 |
+
kwargs.pop('batch_shape', None)
|
| 15 |
+
kwargs.pop('optional', None)
|
| 16 |
+
super().__init__(*args, **kwargs)
|
| 17 |
+
|
| 18 |
+
# Load model with custom object
|
| 19 |
+
model_path = "waste_classifier_patched.h5"
|
| 20 |
+
model = tf.keras.models.load_model(
|
| 21 |
+
model_path,
|
| 22 |
+
compile=False,
|
| 23 |
+
custom_objects={"InputLayer": CompatibleInputLayer}
|
| 24 |
+
)
|
| 25 |
+
print("✅ Model loaded!")
|
| 26 |
|
| 27 |
labels = ["Cardboard", "Glass", "Metal", "Paper", "Plastic", "Trash"]
|
| 28 |
|