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
Upload 2 files
Browse files- app.py +25 -0
- requirements.txt +5 -0
app.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
import numpy as np
|
| 4 |
+
from PIL import Image
|
| 5 |
+
|
| 6 |
+
# Load your model
|
| 7 |
+
model = tf.keras.models.load_model("disaster_mobilenet.keras")
|
| 8 |
+
|
| 9 |
+
# Your class names
|
| 10 |
+
CLASS_NAMES = ["collapsed_building", "fire", "flooded_areas", "normal", "traffic_incident"]
|
| 11 |
+
|
| 12 |
+
def predict(image):
|
| 13 |
+
# Preprocess
|
| 14 |
+
image = image.resize((96,96))
|
| 15 |
+
img_array = np.array(image)/255.0
|
| 16 |
+
img_array = np.expand_dims(img_array, 0) # batch
|
| 17 |
+
|
| 18 |
+
# Predict
|
| 19 |
+
preds = model.predict(img_array)
|
| 20 |
+
class_idx = np.argmax(preds[0])
|
| 21 |
+
return {CLASS_NAMES[i]: float(preds[0][i]) for i in range(len(CLASS_NAMES))}
|
| 22 |
+
|
| 23 |
+
# Gradio interface
|
| 24 |
+
iface = gr.Interface(fn=predict, inputs=gr.Image(type="pil"), outputs=gr.Label())
|
| 25 |
+
iface.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
tensorflow
|
| 2 |
+
gradio
|
| 3 |
+
pillow
|
| 4 |
+
numpy
|
| 5 |
+
python-multipart
|