app.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import sys
|
3 |
+
sys.path.append('./utils')
|
4 |
+
|
5 |
+
from yolo_utils import preprocess_image_pil, run_model, process_results, plot_results_gradio
|
6 |
+
import matplotlib.pyplot as plt
|
7 |
+
import io
|
8 |
+
from ultralytics import YOLO
|
9 |
+
|
10 |
+
def process_image(image,conf,iou):
|
11 |
+
model = YOLO('./trained_models/nano.pt')
|
12 |
+
# Preprocess the image
|
13 |
+
preprocessed_image = preprocess_image_pil(image, threshold_value=0.9, upscale=False)
|
14 |
+
|
15 |
+
# Run the model
|
16 |
+
results = run_model(model, preprocessed_image, conf=conf, iou=iou, imgsz=640)
|
17 |
+
|
18 |
+
# Process the results
|
19 |
+
input_image_array_tensor, seg_result, pred_Phi, sum_pred_H, final_H, dice_loss, tversky_loss = process_results(results, preprocessed_image)
|
20 |
+
|
21 |
+
# Plot the results
|
22 |
+
fig = plot_results_gradio(input_image_array_tensor, seg_result, pred_Phi, sum_pred_H, final_H, dice_loss, tversky_loss)
|
23 |
+
|
24 |
+
# Convert the plot to an image
|
25 |
+
|
26 |
+
return fig
|
27 |
+
|
28 |
+
# Create the Gradio interface
|
29 |
+
title = "YOLOV8-TO Demo App"
|
30 |
+
description = "Upload an image and see the processed results. Adjust the confidence and IOU thresholds as needed."
|
31 |
+
|
32 |
+
iface = gr.Interface(
|
33 |
+
fn=process_image,
|
34 |
+
inputs=[
|
35 |
+
gr.Image(type='pil'),
|
36 |
+
gr.Slider(minimum=0, maximum=1, value=0.1, label="Confidence Threshold"),
|
37 |
+
gr.Slider(minimum=0, maximum=1, value=0.5, label="IOU Threshold")
|
38 |
+
],
|
39 |
+
outputs="image",
|
40 |
+
title=title,
|
41 |
+
description=description
|
42 |
+
)
|
43 |
+
|
44 |
+
iface.launch()
|