|
|
import tensorflow as tf |
|
|
print("TensorFlow is installed:", tf.__version__) |
|
|
|
|
|
import gradio as gr |
|
|
import tensorflow as tf |
|
|
import numpy as np |
|
|
from PIL import Image |
|
|
|
|
|
|
|
|
model = tf.keras.models.load_model("eurosat_cnn_model.h5") |
|
|
|
|
|
|
|
|
class_labels = [ |
|
|
"AnnualCrop", "Forest", "Highway", "Industrial", "Pasture", |
|
|
"PermanentCrop", "Residential", "River", "SeaLake", "HerbaceousVegetation" |
|
|
] |
|
|
|
|
|
|
|
|
def predict_image(image): |
|
|
image = image.resize((64, 64)) |
|
|
img_array = np.array(image) / 255.0 |
|
|
img_array = np.expand_dims(img_array, axis=0) |
|
|
|
|
|
prediction = model.predict(img_array) |
|
|
return {class_labels[i]: float(prediction[0][i]) for i in range(len(class_labels))} |
|
|
|
|
|
|
|
|
iface = gr.Interface(fn=predict_image, inputs="image", outputs="label") |
|
|
iface.launch() |
|
|
|