mayerantoine's picture
fix typos and add explanation
7dc45fe
raw
history blame
1.47 kB
import os
import gradio as gr
import numpy as np
import tensorflow as tf
from tensorflow.keras import models
IMG_SIZE = 300
class_names = ['none','mild','severe']
cwd = os.getcwd()
outpath= os.path.join(cwd,"model")
model_name = 'cross_event_ecuador_haiti_efficientnet_fine_tuned_1644086357.h5'
loaded_model = models.load_model(os.path.join(outpath,model_name))
def _classifier(inp):
img = np.asarray(tf.cast(inp, dtype=tf.float32)) * 1 / 255.0
img = img.reshape((-1, IMG_SIZE, IMG_SIZE, 3))
preds = loaded_model.predict(img).flatten()
return {class_names[i]:float(preds[i]) for i in range(len(class_names))}
iface = gr.Interface(fn=_classifier,
title="Disaster damage assessment from social media image",
description="This simple app allow users to load an image and assess the extent of damage caused by an earthquake",
article="The severity of damage in an image is the extent of physical destruction shown in it. For this experiment we only consider three level of damages: severe damage,mild damage and no damage (none). The model was trained using data from Haiti,Ecuador,Nepal earthquakes and google images.",
examples=['Haiti-Gingerbread-2.jpg','building_damage_100.jpg','building_damage_424.jpg'],
inputs=gr.inputs.Image(shape=(IMG_SIZE, IMG_SIZE)),
outputs=gr.outputs.Label()
)
iface.launch()