Spaces:
Build error
Build error
Upload 3 files
Browse files- .gitattributes +1 -0
- CNN_model.h5 +3 -0
- ResNet50_Model.keras +3 -0
- app.py +61 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
ResNet50_Model.keras filter=lfs diff=lfs merge=lfs -text
|
CNN_model.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:dfc5ab39025e7a777a86f15c17aa65808c8d1e2d20eda935d06cf37e1e12ae02
|
| 3 |
+
size 8267880
|
ResNet50_Model.keras
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4f8c560aa2406ec0a1e7df86e9c9edce634f45fc615791fa452841f5b8d4c1d0
|
| 3 |
+
size 283901240
|
app.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import cv2
|
| 3 |
+
import numpy as np
|
| 4 |
+
from tensorflow.keras.models import load_model
|
| 5 |
+
|
| 6 |
+
# Define the class names
|
| 7 |
+
class_names = ['AnnualCrop', 'Forest', 'HerbaceousVegetation', 'Highway', 'Industrial', 'Pasture', 'PermanentCrop', 'Residential', 'River', 'SeaLake']
|
| 8 |
+
|
| 9 |
+
# Function to load the selected model
|
| 10 |
+
def load_selected_model(model_name):
|
| 11 |
+
if model_name == "ResNet50_Model.keras":
|
| 12 |
+
return load_model('ResNet50_Model.keras')
|
| 13 |
+
elif model_name == "CNN_model.h5":
|
| 14 |
+
return load_model('CNN_model.h5')
|
| 15 |
+
else:
|
| 16 |
+
raise ValueError("Invalid model name")
|
| 17 |
+
|
| 18 |
+
# Function to predict the image
|
| 19 |
+
def predict_image(image, model_name):
|
| 20 |
+
model = load_selected_model(model_name)
|
| 21 |
+
img = cv2.resize(image, (64, 64))
|
| 22 |
+
img = img / 255.0
|
| 23 |
+
img = np.expand_dims(img, axis=0)
|
| 24 |
+
|
| 25 |
+
predictions = model.predict(img)[0]
|
| 26 |
+
|
| 27 |
+
predicted_class_index = np.argmax(predictions)
|
| 28 |
+
predicted_class_name = class_names[predicted_class_index]
|
| 29 |
+
|
| 30 |
+
confidence = predictions[predicted_class_index]
|
| 31 |
+
|
| 32 |
+
# Get the top 3 predictions
|
| 33 |
+
top_indices = predictions.argsort()[-3:][::-1]
|
| 34 |
+
top_classes = [class_names[i] for i in top_indices]
|
| 35 |
+
top_confidences = [predictions[i] for i in top_indices]
|
| 36 |
+
|
| 37 |
+
# Format the output
|
| 38 |
+
result = "Top Predictions:\n"
|
| 39 |
+
for i in range(3):
|
| 40 |
+
result += f"{top_classes[i]} (Confidence: {top_confidences[i]:.2f})\n"
|
| 41 |
+
|
| 42 |
+
return result
|
| 43 |
+
|
| 44 |
+
with gr.Blocks() as demo:
|
| 45 |
+
gr.Markdown("# Area Prediction Angle")
|
| 46 |
+
|
| 47 |
+
with gr.Row():
|
| 48 |
+
with gr.Column():
|
| 49 |
+
model_selector = gr.Dropdown(choices=["ResNet50_Model.keras", "CNN_model.h5"], label="Select Model")
|
| 50 |
+
image_input = gr.Image(type="numpy", label="Upload Image")
|
| 51 |
+
predict_button = gr.Button("Predict")
|
| 52 |
+
|
| 53 |
+
image_output = gr.Image(type="numpy", label="Uploaded Image")
|
| 54 |
+
|
| 55 |
+
prediction_output = gr.Textbox(label="Prediction")
|
| 56 |
+
|
| 57 |
+
predict_button.click(fn=predict_image, inputs=[image_input, model_selector], outputs=prediction_output)
|
| 58 |
+
image_input.change(fn=lambda x: x, inputs=image_input, outputs=image_output)
|
| 59 |
+
|
| 60 |
+
demo.launch()
|
| 61 |
+
|