File size: 1,242 Bytes
abcbc55
 
 
 
 
36a8be7
bb76005
abcbc55
 
36a8be7
abcbc55
 
36a8be7
 
bb76005
36a8be7
abcbc55
36a8be7
abcbc55
 
 
36a8be7
abcbc55
 
bb76005
36a8be7
 
 
00f5f19
 
abcbc55
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import gradio as gr
import tensorflow as tf
from PIL import Image
import numpy as np

# Load the model
model_path = "sentinel_classification_model.keras"
model = tf.keras.models.load_model(model_path)

# Define labels
labels = ['AnnualCrop', 'Forest', 'HerbaceousVegetation', 'Highway', 'Industrial', 'Pasture', 'PermanentCrop', 'Residential', 'River', 'SeaLake']

def predict_image(image):
    image = Image.fromarray(image.astype('uint8'), 'RGB')
    image = image.resize((64, 64)) 
    image = np.array(image)

    prediction = model.predict(np.expand_dims(image, axis=0))
    confidences = {labels[i]: float(prediction[0][i]) for i in range(len(labels))}
    return confidences

# Gradio interface
iface = gr.Interface(
    fn=predict_image,
    inputs=gr.Image(),
    outputs=gr.Label(num_top_classes=10),
    title="Sentinel Image Classifier",
    description="Upload a satellite image and the classifier will predict the type of land cover or feature.",
    examples = ["images/annualcrop.jpg", "images/forest.jpg", "images/herbaceousvegetation.jpg", "images/highway.jpg", "images/industrial.jpg", "images/pasture.jpg", "images/permanentcrop.jpg", "images/residential.jpg", "images/river.jpg", "images/sealake.jpg"]

)

iface.launch()