File size: 2,912 Bytes
b8d9f69 115ddf5 b8d9f69 d9db1f6 115ddf5 d9db1f6 115ddf5 d9db1f6 b8d9f69 115ddf5 b8d9f69 d9db1f6 b8d9f69 d9db1f6 b8d9f69 d9db1f6 b8d9f69 d9db1f6 b8d9f69 d9db1f6 b8d9f69 d9db1f6 b8d9f69 d9db1f6 b8d9f69 115ddf5 b8d9f69 d9db1f6 b8d9f69 d9db1f6 b8d9f69 |
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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
#!/usr/bin/env python
import json
import pathlib
import shlex
import subprocess
import gradio as gr
def run(image_path: str, class_index: int, scale: str, sigma_y: float) -> str:
out_name = image_path.split("/")[-1].split(".")[0]
subprocess.run( # noqa: S603
shlex.split(
f"python main.py --config confs/inet256.yml --resize_y --deg sr_averagepooling --scale {scale} --class {class_index} --path_y {image_path} --save_path {out_name} --sigma_y {sigma_y}"
),
cwd="DDNM/hq_demo",
check=False,
)
return f"DDNM/hq_demo/results/{out_name}/final/00000.png"
def create_demo() -> gr.Blocks:
examples = [
[
"DDNM/hq_demo/data/datasets/gts/inet256/323.png",
"monarch, monarch butterfly, milkweed butterfly, Danaus plexippus",
"4",
0,
],
[
"DDNM/hq_demo/data/datasets/gts/inet256/orange.png",
"orange",
"4",
0,
],
[
"DDNM/hq_demo/data/datasets/gts/inet256/monarch.png",
"monarch, monarch butterfly, milkweed butterfly, Danaus plexippus",
"4",
0.5,
],
[
"DDNM/hq_demo/data/datasets/gts/inet256/bear.png",
"brown bear, bruin, Ursus arctos",
"4",
0,
],
[
"DDNM/hq_demo/data/datasets/gts/inet256/flamingo.png",
"flamingo",
"2",
0,
],
[
"DDNM/hq_demo/data/datasets/gts/inet256/kimono.png",
"kimono",
"2",
0,
],
[
"DDNM/hq_demo/data/datasets/gts/inet256/zebra.png",
"zebra",
"4",
0,
],
]
with pathlib.Path("imagenet_classes.json").open() as f:
imagenet_class_names = json.load(f)
with gr.Blocks() as demo:
with gr.Row():
with gr.Column():
image = gr.Image(label="Input image", type="filepath")
class_index = gr.Dropdown(label="Class name", choices=imagenet_class_names, type="index", value=950)
scale = gr.Dropdown(label="Scale", choices=["2", "4", "8"], value="4")
sigma_y = gr.Number(label="sigma_y", value=0, precision=2)
run_button = gr.Button("Run")
with gr.Column():
result = gr.Image(label="Result", type="filepath")
gr.Examples(
examples=examples,
inputs=[
image,
class_index,
scale,
sigma_y,
],
)
run_button.click(
fn=run,
inputs=[
image,
class_index,
scale,
sigma_y,
],
outputs=result,
)
return demo
|