Spaces:
Sleeping
Sleeping
Nunzio commited on
Commit ·
66bf19a
1
Parent(s): 71771bf
better code
Browse files- app.py +4 -9
- utils/imageHandling.py +2 -2
app.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
-
import torch
|
| 2 |
import gradio as gr
|
| 3 |
-
from PIL import Image
|
| 4 |
|
| 5 |
from utils.imageHandling import hfImageToTensor, preprocessing, postprocessing, loadPreloadedImages
|
| 6 |
from model.modelLoading import loadBiSeNet, loadBiSeNetV2
|
|
@@ -18,8 +17,6 @@ MODELS = {
|
|
| 18 |
"BISENETV2": loadBiSeNetV2(device)
|
| 19 |
}
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
image_list = loadPreloadedImages(gta_image_dir, city_image_dir, turin_image_dir)
|
| 24 |
|
| 25 |
|
|
@@ -83,16 +80,14 @@ with gr.Blocks(title="Semantic Segmentation Predictors") as demo:
|
|
| 83 |
with gr.Row():
|
| 84 |
gr.Markdown("## Preloaded images to be used for testing the model")
|
| 85 |
gr.Markdown("You can use images from the Grand Theft Auto V video game, the Cityscapes dataset or even from Turin")
|
| 86 |
-
def set_image(image):
|
| 87 |
-
return image
|
| 88 |
|
| 89 |
# Mostriamo 4 righe da 5 immagini
|
| 90 |
for i in range(0, len(image_list), 5):
|
| 91 |
with gr.Row():
|
| 92 |
-
for img
|
| 93 |
-
img_comp = gr.Image(value=img, interactive=False, show_label=False, show_download_button=False, height=
|
| 94 |
show_fullscreen_button=False, show_share_button=False, mirror_webcam=False)
|
| 95 |
-
img_comp.select(fn=
|
| 96 |
|
| 97 |
submit_btn.click(
|
| 98 |
fn=run_prediction,
|
|
|
|
| 1 |
+
import torch
|
| 2 |
import gradio as gr
|
|
|
|
| 3 |
|
| 4 |
from utils.imageHandling import hfImageToTensor, preprocessing, postprocessing, loadPreloadedImages
|
| 5 |
from model.modelLoading import loadBiSeNet, loadBiSeNetV2
|
|
|
|
| 17 |
"BISENETV2": loadBiSeNetV2(device)
|
| 18 |
}
|
| 19 |
|
|
|
|
|
|
|
| 20 |
image_list = loadPreloadedImages(gta_image_dir, city_image_dir, turin_image_dir)
|
| 21 |
|
| 22 |
|
|
|
|
| 80 |
with gr.Row():
|
| 81 |
gr.Markdown("## Preloaded images to be used for testing the model")
|
| 82 |
gr.Markdown("You can use images from the Grand Theft Auto V video game, the Cityscapes dataset or even from Turin")
|
|
|
|
|
|
|
| 83 |
|
| 84 |
# Mostriamo 4 righe da 5 immagini
|
| 85 |
for i in range(0, len(image_list), 5):
|
| 86 |
with gr.Row():
|
| 87 |
+
for img in image_list[i:i+5]:
|
| 88 |
+
img_comp = gr.Image(value=img, interactive=False, show_label=False, show_download_button=False, height=180, width=256,
|
| 89 |
show_fullscreen_button=False, show_share_button=False, mirror_webcam=False)
|
| 90 |
+
img_comp.select(fn=lambda x:x, inputs=img_comp, outputs=image_input)
|
| 91 |
|
| 92 |
submit_btn.click(
|
| 93 |
fn=run_prediction,
|
utils/imageHandling.py
CHANGED
|
@@ -95,5 +95,5 @@ def loadPreloadedImages(*args:str) -> list[tuple[Image.Image, str]]:
|
|
| 95 |
Returns:
|
| 96 |
images (list[tuple[Image.Image, str]]): List of loaded images with their original paths.
|
| 97 |
"""
|
| 98 |
-
return sorted([[Image.open(os.path.join(imageDir, image)).convert("RGB"), os.path.join(imageDir, image)]
|
| 99 |
-
for imageDir in args for image in os.listdir(imageDir) if image.endswith((".png", ".jpg", "jpeg"))], key=lambda x: x[1])
|
|
|
|
| 95 |
Returns:
|
| 96 |
images (list[tuple[Image.Image, str]]): List of loaded images with their original paths.
|
| 97 |
"""
|
| 98 |
+
return list(map(lambda x:x[0], sorted([[Image.open(os.path.join(imageDir, image)).convert("RGB"), os.path.join(imageDir, image)]
|
| 99 |
+
for imageDir in args for image in os.listdir(imageDir) if image.endswith((".png", ".jpg", "jpeg"))], key=lambda x: x[1])))
|