Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,7 +7,25 @@ with CustomObjectScope({'RandomHeight': RandomHeight}):
|
|
| 7 |
model_0 = tf.keras.models.load_model('bestmodel.h5')
|
| 8 |
|
| 9 |
def classify_image(inp):
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
prediction = model_0.predict(inp)
|
| 12 |
output = ""
|
| 13 |
if prediction[0][prediction.argmax()] < 0.84:
|
|
|
|
| 7 |
model_0 = tf.keras.models.load_model('bestmodel.h5')
|
| 8 |
|
| 9 |
def classify_image(inp):
|
| 10 |
+
# Convert to PIL Image if we have a numpy array
|
| 11 |
+
if isinstance(image_array, np.ndarray):
|
| 12 |
+
image = Image.fromarray(image_array)
|
| 13 |
+
else:
|
| 14 |
+
image = image_array
|
| 15 |
+
|
| 16 |
+
# Resize image to 224x224
|
| 17 |
+
image = image.resize((224, 224), Image.Resampling.LANCZOS)
|
| 18 |
+
|
| 19 |
+
# Convert to numpy array and ensure correct shape
|
| 20 |
+
image_array = np.array(image)
|
| 21 |
+
|
| 22 |
+
# Handle grayscale images
|
| 23 |
+
if len(image_array.shape) == 2:
|
| 24 |
+
image_array = np.stack([image_array] * 3, axis=-1)
|
| 25 |
+
|
| 26 |
+
# Add batch dimension and ensure correct shape
|
| 27 |
+
inp = image_array.reshape((-1, 224, 224, 3))
|
| 28 |
+
# inp = inp.reshape((-1, 224, 224, 3))
|
| 29 |
prediction = model_0.predict(inp)
|
| 30 |
output = ""
|
| 31 |
if prediction[0][prediction.argmax()] < 0.84:
|