Instructions to use w-samik/Disaster_Detection with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use w-samik/Disaster_Detection with Keras:
# !pip install -U keras tensorflow huggingface_hub # Keras needs TensorFlow installed to read "hf://" paths, so the tensorflow backend is selected here; # "jax" and "torch" also work for computation once TensorFlow is installed. import os os.environ["KERAS_BACKEND"] = "tensorflow" import keras model = keras.saving.load_model("hf://w-samik/Disaster_Detection") - Notebooks
- Google Colab
- Kaggle
File size: 758 Bytes
105adec | 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 | import gradio as gr
import tensorflow as tf
import numpy as np
from PIL import Image
# Load your model
model = tf.keras.models.load_model("disaster_mobilenet.keras")
# Your class names
CLASS_NAMES = ["collapsed_building", "fire", "flooded_areas", "normal", "traffic_incident"]
def predict(image):
# Preprocess
image = image.resize((96,96))
img_array = np.array(image)/255.0
img_array = np.expand_dims(img_array, 0) # batch
# Predict
preds = model.predict(img_array)
class_idx = np.argmax(preds[0])
return {CLASS_NAMES[i]: float(preds[0][i]) for i in range(len(CLASS_NAMES))}
# Gradio interface
iface = gr.Interface(fn=predict, inputs=gr.Image(type="pil"), outputs=gr.Label())
iface.launch()
|