bugfix
Browse files
app.py
CHANGED
|
@@ -3,38 +3,32 @@ import tensorflow as tf
|
|
| 3 |
from PIL import Image
|
| 4 |
import numpy as np
|
| 5 |
|
| 6 |
-
|
|
|
|
| 7 |
model = tf.keras.models.load_model(model_path)
|
| 8 |
|
| 9 |
-
|
| 10 |
labels = ['AnnualCrop', 'Forest', 'HerbaceousVegetation', 'Highway', 'Industrial', 'Pasture', 'PermanentCrop', 'Residential', 'River', 'SeaLake']
|
| 11 |
-
|
| 12 |
-
def predict_image(image):
|
| 13 |
-
|
| 14 |
-
image = Image.fromarray(image.astype('uint8'))
|
| 15 |
-
image = image.resize((128, 128))
|
| 16 |
-
image = np.array(image) / 255.0
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
| 21 |
|
| 22 |
-
|
|
|
|
| 23 |
confidences = {labels[i]: float(prediction[0][i]) for i in range(len(labels))}
|
| 24 |
return confidences
|
| 25 |
|
| 26 |
|
| 27 |
-
|
| 28 |
-
output_text = gr.Textbox(label="Predicted Value")
|
| 29 |
-
|
| 30 |
-
|
| 31 |
iface = gr.Interface(
|
| 32 |
fn=predict_image,
|
| 33 |
-
inputs=
|
| 34 |
-
outputs=gr.Label(),
|
| 35 |
-
title="Sentinel Classifier",
|
| 36 |
-
|
| 37 |
-
|
| 38 |
)
|
| 39 |
|
| 40 |
|
|
|
|
| 3 |
from PIL import Image
|
| 4 |
import numpy as np
|
| 5 |
|
| 6 |
+
# Load the model
|
| 7 |
+
model_path = "sentinel_classificatiion_model.keras"
|
| 8 |
model = tf.keras.models.load_model(model_path)
|
| 9 |
|
| 10 |
+
# Define labels
|
| 11 |
labels = ['AnnualCrop', 'Forest', 'HerbaceousVegetation', 'Highway', 'Industrial', 'Pasture', 'PermanentCrop', 'Residential', 'River', 'SeaLake']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
def predict_image(image):
|
| 14 |
+
image = Image.fromarray(image.astype('uint8'), 'RGB')
|
| 15 |
+
image = image.resize((64, 64))
|
| 16 |
+
image = np.array(image)
|
| 17 |
|
| 18 |
+
print("Min and max values:", image.min(), image.max()) # Sollte zwischen 0 und 1 sein
|
| 19 |
+
prediction = model.predict(np.expand_dims(image, axis=0))
|
| 20 |
confidences = {labels[i]: float(prediction[0][i]) for i in range(len(labels))}
|
| 21 |
return confidences
|
| 22 |
|
| 23 |
|
| 24 |
+
# Gradio interface
|
|
|
|
|
|
|
|
|
|
| 25 |
iface = gr.Interface(
|
| 26 |
fn=predict_image,
|
| 27 |
+
inputs=gr.Image(shape=(128, 128)),
|
| 28 |
+
outputs=gr.Label(num_top_classes=10),
|
| 29 |
+
title="Sentinel Image Classifier",
|
| 30 |
+
description="Upload a satellite image and the classifier will predict the type of land cover or feature.",
|
| 31 |
+
examples=["images/forest.jpg", "images/highway.jpg", "images/industrial.jpg", "images/residential.jpg", "images/river.jpg"]
|
| 32 |
)
|
| 33 |
|
| 34 |
|