Upload folder using huggingface_hub
Browse files- README.md +3 -9
- ct_seg_gradio.py +117 -0
- cxr_gradio.py +77 -0
- cxr_seg_gradio.py +113 -0
- lung_seg_gradio.py +113 -0
- lung_seg_ranks/0.txt +1 -0
- test_gradio.py +43 -0
- test_gradio_2.py +43 -0
README.md
CHANGED
@@ -1,12 +1,6 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
|
4 |
-
colorFrom: blue
|
5 |
-
colorTo: purple
|
6 |
sdk: gradio
|
7 |
-
sdk_version:
|
8 |
-
app_file: app.py
|
9 |
-
pinned: false
|
10 |
---
|
11 |
-
|
12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
+
title: gradio
|
3 |
+
app_file: ct_seg_gradio.py
|
|
|
|
|
4 |
sdk: gradio
|
5 |
+
sdk_version: 3.47.1
|
|
|
|
|
6 |
---
|
|
|
|
ct_seg_gradio.py
ADDED
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import random
|
3 |
+
import time
|
4 |
+
import os
|
5 |
+
from glob import glob
|
6 |
+
from PIL import Image
|
7 |
+
import torchvision.transforms as transforms
|
8 |
+
|
9 |
+
num_rank = 200
|
10 |
+
image_prefix = "/deep/u/eprakash/AngioSeg/diffusion/ct_synthetic_60/synth/"
|
11 |
+
mask_prefix = "/deep/u/eprakash/ct/orig_masks/"
|
12 |
+
image_ids = []
|
13 |
+
mask_ids = []
|
14 |
+
img_list = "/deep/u/eprakash/ct/train_60.csv"
|
15 |
+
with open(img_list) as fp:
|
16 |
+
for line in fp:
|
17 |
+
ex = line.strip().split(",")[0]
|
18 |
+
mask_ids.append(ex.split("_")[0] + "_mask_" + ex.split("_")[1])
|
19 |
+
image_ids.append("('" + ex + "',)")
|
20 |
+
image_ids = image_ids[301:501]
|
21 |
+
mask_ids = mask_ids[301:501]
|
22 |
+
save_path = "ct_seg_ranks"
|
23 |
+
|
24 |
+
def is_int(s):
|
25 |
+
try:
|
26 |
+
int(s)
|
27 |
+
return True
|
28 |
+
except ValueError:
|
29 |
+
return False
|
30 |
+
|
31 |
+
def load_img(img_path, size=512):
|
32 |
+
img = Image.open(img_path).convert('RGB')
|
33 |
+
transform_list = [transforms.Resize((size, size))]
|
34 |
+
transform = transforms.Compose(transform_list)
|
35 |
+
img = transform(img)
|
36 |
+
return img
|
37 |
+
|
38 |
+
def find_completed_idxs(save_path=save_path):
|
39 |
+
files = os.listdir(save_path)
|
40 |
+
incorrect_files = []
|
41 |
+
if len(files) == 0:
|
42 |
+
return [-1], []
|
43 |
+
else:
|
44 |
+
file_list = []
|
45 |
+
for f in files:
|
46 |
+
f_name = int(f.split(".")[0])
|
47 |
+
with open(save_path + "/" + f) as fp:
|
48 |
+
for line in fp:
|
49 |
+
items = line.strip().split(",")
|
50 |
+
if (len(items) != 5 and f_name != -1):
|
51 |
+
incorrect_files.append(f_name)
|
52 |
+
else:
|
53 |
+
if ((not is_int(items[1].strip()) or not is_int(items[2].strip()) or not is_int(items[3].strip()) or not is_int(items[4].strip())) and f_name != -1):
|
54 |
+
incorrect_files.append(f_name)
|
55 |
+
file_list.append(f_name)
|
56 |
+
file_list = sorted(file_list)
|
57 |
+
incorrect_files = sorted(incorrect_files)
|
58 |
+
return file_list, incorrect_files
|
59 |
+
|
60 |
+
def load_next(rank, img_1, mask_1, img_2, mask_2, img_3, mask_3, img_4, mask_4, example, ids=image_ids, image_prefix=image_prefix, save_path=save_path):
|
61 |
+
file_list, incorrect_files = find_completed_idxs()
|
62 |
+
print(str(file_list) + " " + str(incorrect_files))
|
63 |
+
if (int(example) not in file_list or int(example) in incorrect_files):
|
64 |
+
r = str(image_ids[int(example)]).split(",")[0].split("(")[1] + "," + rank
|
65 |
+
r_fp = open(save_path + "/" + str(int(example)) +".txt", "w")
|
66 |
+
r_fp.write(r + "\n")
|
67 |
+
r_fp.close()
|
68 |
+
file_list, incorrect_files = find_completed_idxs()
|
69 |
+
if (len(incorrect_files) != 0):
|
70 |
+
example = incorrect_files[-1]
|
71 |
+
else:
|
72 |
+
example = file_list[-1] + 1
|
73 |
+
if int(example) == num_rank:
|
74 |
+
rank = "DONE!"
|
75 |
+
example = -1
|
76 |
+
mask_1 = gr.Image(label="Mask", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
77 |
+
img_1 = gr.Image(label="Sample #1", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
78 |
+
mask_2 = gr.Image(label="Mask", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
79 |
+
img_2 = gr.Image(label="Sample #2", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
80 |
+
mask_3 = gr.Image(label="Mask", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
81 |
+
img_3 = gr.Image(label="Sample #3", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
82 |
+
mask_4 = gr.Image(label="Mask", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
83 |
+
img_4 = gr.Image(label="Sample #4", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
84 |
+
else:
|
85 |
+
rank = ""
|
86 |
+
img_1 = gr.Image(label="Sample #1", value=load_img(image_prefix + str(image_ids[int(example)]) + "_synthetic_0.png"), interactive=False)
|
87 |
+
mask_1 = gr.Image(label="Mask", value=load_img(mask_prefix + str(mask_ids[int(example)]) + ".jpg"), interactive=False)
|
88 |
+
img_2 = gr.Image(label="Sample #2", value=load_img(image_prefix+ str(image_ids[int(example)]) + "_synthetic_1.png"), interactive=False)
|
89 |
+
mask_2 = gr.Image(label="Mask", value=load_img(mask_prefix + str(mask_ids[int(example)]) + ".jpg"), interactive=False)
|
90 |
+
img_3 = gr.Image(label="Sample #3", value=load_img(image_prefix + str(image_ids[int(example)]) + "_synthetic_2.png"), interactive=False)
|
91 |
+
mask_3 = gr.Image(label="Mask", value=load_img(mask_prefix + str(mask_ids[int(example)]) + ".jpg"), interactive=False)
|
92 |
+
img_4 = gr.Image(label="Sample #4", value=load_img(image_prefix + str(image_ids[int(example)]) + "_synthetic_3.png"), interactive=False)
|
93 |
+
mask_4 = gr.Image(label="Mask", value=load_img(mask_prefix + str(mask_ids[int(example)]) + ".jpg"), interactive=False)
|
94 |
+
return [rank, img_1, mask_1, img_2, mask_2, img_3, mask_3, img_4, mask_4, example]
|
95 |
+
|
96 |
+
with gr.Blocks() as demo:
|
97 |
+
last_idx = -1
|
98 |
+
example = gr.Number(label="Example #. Click next for #-1 (blank starting page).", value=last_idx, interactive=False)
|
99 |
+
rank = gr.Textbox(label="Rankings (Best to worst, comma-separated, no spaces).")
|
100 |
+
with gr.Column(scale=1):
|
101 |
+
with gr.Row():
|
102 |
+
mask_1 = gr.Image(label="Mask", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
103 |
+
img_1 = gr.Image(label="Sample #1", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
104 |
+
with gr.Row():
|
105 |
+
mask_2 = gr.Image(label="Mask", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
106 |
+
img_2 = gr.Image(label="Sample #2", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
107 |
+
with gr.Row():
|
108 |
+
mask_3 = gr.Image(label="Mask", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
109 |
+
img_3 = gr.Image(label="Sample #3", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
110 |
+
with gr.Row():
|
111 |
+
mask_4 = gr.Image(label="Mask", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
112 |
+
img_4 = gr.Image(label="Sample #4", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
113 |
+
next_btn = gr.Button(value="Next")
|
114 |
+
next_btn.click(fn=load_next, inputs=[rank, img_1, mask_1, img_2, mask_2, img_3, mask_3, img_4, mask_4, example], outputs=[rank, img_1, mask_1, img_2, mask_2, img_3, mask_3, img_4, mask_4, example], queue=False)
|
115 |
+
demo.queue()
|
116 |
+
demo.launch(share=True)
|
117 |
+
|
cxr_gradio.py
ADDED
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import random
|
3 |
+
import time
|
4 |
+
import os
|
5 |
+
from glob import glob
|
6 |
+
from PIL import Image
|
7 |
+
import torchvision.transforms as transforms
|
8 |
+
|
9 |
+
image_prefix = "/deep/u/eprakash/AngioSeg/diffusion/cxr_synthetic_data_25_no_transform/synth/"
|
10 |
+
image_ids = glob(os.path.join(image_prefix, '*' + '.png'))
|
11 |
+
image_ids = list(set([os.path.splitext(os.path.basename(p))[0].split("_")[0] for p in image_ids]))
|
12 |
+
save_path = "cxr_ranks"
|
13 |
+
|
14 |
+
def load_img(img_path, size=1024):
|
15 |
+
img = Image.open(img_path).convert('RGB')
|
16 |
+
transform_list = [transforms.Resize((size, size))]
|
17 |
+
transform = transforms.Compose(transform_list)
|
18 |
+
img = transform(img)
|
19 |
+
return img
|
20 |
+
|
21 |
+
def find_completed_idxs(save_path=save_path):
|
22 |
+
files = os.listdir(save_path)
|
23 |
+
if len(files) == 0:
|
24 |
+
return [-1]
|
25 |
+
else:
|
26 |
+
file_list = []
|
27 |
+
for f in files:
|
28 |
+
f = int(f.split(".")[0])
|
29 |
+
file_list.append(f)
|
30 |
+
file_list = sorted(file_list)
|
31 |
+
return file_list
|
32 |
+
|
33 |
+
def load_next(rank, img_1, mask_1, img_2, mask_2, img_3, mask_3, img_4, mask_4, example, ids=image_ids, image_prefix=image_prefix, save_path=save_path):
|
34 |
+
if int(example) == len(image_ids) - 1:
|
35 |
+
return [None, None, None, None, None, None, None]
|
36 |
+
else:
|
37 |
+
file_list = find_completed_idxs()
|
38 |
+
if (int(example) not in file_list):
|
39 |
+
r = str(image_ids[int(example)]) + "," + rank
|
40 |
+
r_fp = open(save_path + "/" + str(int(example)) +".txt", "w")
|
41 |
+
r_fp.write(r + "\n")
|
42 |
+
r_fp.close()
|
43 |
+
file_list = find_completed_idxs()
|
44 |
+
example = file_list[-1] + 1
|
45 |
+
rank = ""
|
46 |
+
img_1 = gr.Image(label="Sample #1", value=load_img(image_prefix + str(image_ids[int(example)]) + "_synthetic_0.png"), interactive=False)
|
47 |
+
mask_1 = gr.Image(label="Mask", value=load_img(image_prefix + str(image_ids[int(example)]) + "_synthetic_mask_1.png"), interactive=False)
|
48 |
+
img_2 = gr.Image(label="Sample #2", value=load_img(image_prefix+ str(image_ids[int(example)]) + "_synthetic_1.png"), interactive=False)
|
49 |
+
mask_2 = gr.Image(label="Mask", value=load_img(image_prefix + str(image_ids[int(example)]) + "_synthetic_mask_2.png"), interactive=False)
|
50 |
+
img_3 = gr.Image(label="Sample #3", value=load_img(image_prefix + str(image_ids[int(example)]) + "_synthetic_2.png"), interactive=False)
|
51 |
+
mask_3 = gr.Image(label="Mask", value=load_img(image_prefix + str(image_ids[int(example)]) + "_synthetic_mask_3.png"), interactive=False)
|
52 |
+
img_4 = gr.Image(label="Sample #4", value=load_img(image_prefix + str(image_ids[int(example)]) + "_synthetic_3.png"), interactive=False)
|
53 |
+
mask_4 = gr.Image(label="Mask", value=load_img(image_prefix + str(image_ids[int(example)]) + "_synthetic_mask_4.png"), interactive=False)
|
54 |
+
return [rank, img_1, mask_1, img_2, mask_2, img_3, mask_3, img_4, mask_4, example]
|
55 |
+
|
56 |
+
with gr.Blocks() as demo:
|
57 |
+
last_idx = -1
|
58 |
+
example = gr.Number(label="Example #. Click next for #-1 (blank starting page).", value=last_idx, interactive=False)
|
59 |
+
rank = gr.Textbox(label="Rankings (Best to worst, comma-separated, no spaces).")
|
60 |
+
with gr.Column(scale=1):
|
61 |
+
with gr.Row():
|
62 |
+
mask_1 = gr.Image(label="Mask", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
63 |
+
img_1 = gr.Image(label="Sample #1", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
64 |
+
with gr.Row():
|
65 |
+
mask_2 = gr.Image(label="Mask", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
66 |
+
img_2 = gr.Image(label="Sample #2", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
67 |
+
with gr.Row():
|
68 |
+
mask_3 = gr.Image(label="Mask", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
69 |
+
img_3 = gr.Image(label="Sample #3", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
70 |
+
with gr.Row():
|
71 |
+
mask_4 = gr.Image(label="Mask", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
72 |
+
img_4 = gr.Image(label="Sample #4", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
73 |
+
next_btn = gr.Button(value="Next")
|
74 |
+
next_btn.click(fn=load_next, inputs=[rank, img_1, mask_1, img_2, mask_2, img_3, mask_3, img_4, mask_4, example], outputs=[rank, img_1, mask_1, img_2, mask_2, img_3, mask_3, img_4, mask_4, example], queue=False)
|
75 |
+
demo.queue()
|
76 |
+
demo.launch(share=True)
|
77 |
+
|
cxr_seg_gradio.py
ADDED
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import random
|
3 |
+
import time
|
4 |
+
import os
|
5 |
+
from glob import glob
|
6 |
+
from PIL import Image
|
7 |
+
import torchvision.transforms as transforms
|
8 |
+
|
9 |
+
save_path = "cxr_seg_ranks"
|
10 |
+
num_rank = 200
|
11 |
+
image_prefix = "/deep/u/eprakash/AngioSeg/diffusion/cxr_synthetic_60/synth/"
|
12 |
+
mask_prefix = "/deep/u/eprakash/AngioSeg/diffusion/cxr_synthetic_60/orig/"
|
13 |
+
image_ids = []
|
14 |
+
img_list = "/deep/u/eprakash/cxr/train_non_25.csv"
|
15 |
+
with open(img_list) as fp:
|
16 |
+
for line in fp:
|
17 |
+
image_ids.append("('" + line.strip().split(",")[0] + "',)")
|
18 |
+
image_ids = image_ids[301:501]
|
19 |
+
|
20 |
+
def is_int(s):
|
21 |
+
try:
|
22 |
+
int(s)
|
23 |
+
return True
|
24 |
+
except ValueError:
|
25 |
+
return False
|
26 |
+
|
27 |
+
def load_img(img_path, size=512):
|
28 |
+
img = Image.open(img_path).convert('RGB')
|
29 |
+
transform_list = [transforms.Resize((size, size))]
|
30 |
+
transform = transforms.Compose(transform_list)
|
31 |
+
img = transform(img)
|
32 |
+
return img
|
33 |
+
|
34 |
+
def find_completed_idxs(save_path=save_path):
|
35 |
+
files = os.listdir(save_path)
|
36 |
+
incorrect_files = []
|
37 |
+
if len(files) == 0:
|
38 |
+
return [-1], []
|
39 |
+
else:
|
40 |
+
file_list = []
|
41 |
+
for f in files:
|
42 |
+
f_name = int(f.split(".")[0])
|
43 |
+
with open(save_path + "/" + f) as fp:
|
44 |
+
for line in fp:
|
45 |
+
items = line.strip().split(",")
|
46 |
+
if (len(items) != 5 and f_name != -1):
|
47 |
+
incorrect_files.append(f_name)
|
48 |
+
else:
|
49 |
+
if ((not is_int(items[1].strip()) or not is_int(items[2].strip()) or not is_int(items[3].strip()) or not is_int(items[4].strip())) and f_name != -1):
|
50 |
+
incorrect_files.append(f_name)
|
51 |
+
file_list.append(f_name)
|
52 |
+
file_list = sorted(file_list)
|
53 |
+
incorrect_files = sorted(incorrect_files)
|
54 |
+
return file_list, incorrect_files
|
55 |
+
|
56 |
+
def load_next(rank, img_1, mask_1, img_2, mask_2, img_3, mask_3, img_4, mask_4, example, ids=image_ids, image_prefix=image_prefix, save_path=save_path):
|
57 |
+
file_list, incorrect_files = find_completed_idxs()
|
58 |
+
print(str(file_list) + " " + str(incorrect_files))
|
59 |
+
if (int(example) not in file_list or int(example) in incorrect_files):
|
60 |
+
r = str(image_ids[int(example)]).split(",")[0].split("(")[1] + "," + rank
|
61 |
+
r_fp = open(save_path + "/" + str(int(example)) +".txt", "w")
|
62 |
+
r_fp.write(r + "\n")
|
63 |
+
r_fp.close()
|
64 |
+
file_list, incorrect_files = find_completed_idxs()
|
65 |
+
if (len(incorrect_files) != 0):
|
66 |
+
example = incorrect_files[-1]
|
67 |
+
else:
|
68 |
+
example = file_list[-1] + 1
|
69 |
+
if int(example) == num_rank:
|
70 |
+
rank = "DONE!"
|
71 |
+
example = -1
|
72 |
+
mask_1 = gr.Image(label="Mask", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
73 |
+
img_1 = gr.Image(label="Sample #1", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
74 |
+
mask_2 = gr.Image(label="Mask", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
75 |
+
img_2 = gr.Image(label="Sample #2", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
76 |
+
mask_3 = gr.Image(label="Mask", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
77 |
+
img_3 = gr.Image(label="Sample #3", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
78 |
+
mask_4 = gr.Image(label="Mask", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
79 |
+
img_4 = gr.Image(label="Sample #4", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
80 |
+
else:
|
81 |
+
rank = ""
|
82 |
+
img_1 = gr.Image(label="Sample #1", value=load_img(image_prefix + str(image_ids[int(example)]) + "_synthetic_0.png"), interactive=False)
|
83 |
+
mask_1 = gr.Image(label="Mask", value=load_img(mask_prefix + str(image_ids[int(example)]) + "_mask.png"), interactive=False)
|
84 |
+
img_2 = gr.Image(label="Sample #2", value=load_img(image_prefix+ str(image_ids[int(example)]) + "_synthetic_1.png"), interactive=False)
|
85 |
+
mask_2 = gr.Image(label="Mask", value=load_img(mask_prefix + str(image_ids[int(example)]) + "_mask.png"), interactive=False)
|
86 |
+
img_3 = gr.Image(label="Sample #3", value=load_img(image_prefix + str(image_ids[int(example)]) + "_synthetic_2.png"), interactive=False)
|
87 |
+
mask_3 = gr.Image(label="Mask", value=load_img(mask_prefix + str(image_ids[int(example)]) + "_mask.png"), interactive=False)
|
88 |
+
img_4 = gr.Image(label="Sample #4", value=load_img(image_prefix + str(image_ids[int(example)]) + "_synthetic_3.png"), interactive=False)
|
89 |
+
mask_4 = gr.Image(label="Mask", value=load_img(mask_prefix + str(image_ids[int(example)]) + "_mask.png"), interactive=False)
|
90 |
+
return [rank, img_1, mask_1, img_2, mask_2, img_3, mask_3, img_4, mask_4, example]
|
91 |
+
|
92 |
+
with gr.Blocks() as demo:
|
93 |
+
last_idx = -1
|
94 |
+
example = gr.Number(label="Example #. Click next for #-1 (blank starting page).", value=last_idx, interactive=False)
|
95 |
+
rank = gr.Textbox(label="Rankings (Best to worst, comma-separated, no spaces).")
|
96 |
+
with gr.Column(scale=1):
|
97 |
+
with gr.Row():
|
98 |
+
mask_1 = gr.Image(label="Mask", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
99 |
+
img_1 = gr.Image(label="Sample #1", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
100 |
+
with gr.Row():
|
101 |
+
mask_2 = gr.Image(label="Mask", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
102 |
+
img_2 = gr.Image(label="Sample #2", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
103 |
+
with gr.Row():
|
104 |
+
mask_3 = gr.Image(label="Mask", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
105 |
+
img_3 = gr.Image(label="Sample #3", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
106 |
+
with gr.Row():
|
107 |
+
mask_4 = gr.Image(label="Mask", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
108 |
+
img_4 = gr.Image(label="Sample #4", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
109 |
+
next_btn = gr.Button(value="Next")
|
110 |
+
next_btn.click(fn=load_next, inputs=[rank, img_1, mask_1, img_2, mask_2, img_3, mask_3, img_4, mask_4, example], outputs=[rank, img_1, mask_1, img_2, mask_2, img_3, mask_3, img_4, mask_4, example], queue=False)
|
111 |
+
demo.queue()
|
112 |
+
demo.launch(share=True)
|
113 |
+
|
lung_seg_gradio.py
ADDED
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import random
|
3 |
+
import time
|
4 |
+
import os
|
5 |
+
from glob import glob
|
6 |
+
from PIL import Image
|
7 |
+
import torchvision.transforms as transforms
|
8 |
+
|
9 |
+
num_rank = 200
|
10 |
+
image_prefix = "/deep/u/eprakash/AngioSeg/diffusion/lung_seg_synthetic_60/synth/"
|
11 |
+
mask_prefix = "/deep/u/eprakash/AngioSeg/diffusion/lung_seg_synthetic_60/orig/"
|
12 |
+
image_ids = []
|
13 |
+
img_list = "/deep/u/eprakash/lung_seg/train_60.csv"
|
14 |
+
with open(img_list) as fp:
|
15 |
+
for line in fp:
|
16 |
+
image_ids.append("('" + line.strip().split(",")[0] + "',)")
|
17 |
+
image_ids = image_ids[301:501]
|
18 |
+
save_path = "lung_seg_ranks"
|
19 |
+
|
20 |
+
def is_int(s):
|
21 |
+
try:
|
22 |
+
int(s)
|
23 |
+
return True
|
24 |
+
except ValueError:
|
25 |
+
return False
|
26 |
+
|
27 |
+
def load_img(img_path, size=512):
|
28 |
+
img = Image.open(img_path).convert('RGB')
|
29 |
+
transform_list = [transforms.Resize((size, size))]
|
30 |
+
transform = transforms.Compose(transform_list)
|
31 |
+
img = transform(img)
|
32 |
+
return img
|
33 |
+
|
34 |
+
def find_completed_idxs(save_path=save_path):
|
35 |
+
files = os.listdir(save_path)
|
36 |
+
incorrect_files = []
|
37 |
+
if len(files) == 0:
|
38 |
+
return [-1], []
|
39 |
+
else:
|
40 |
+
file_list = []
|
41 |
+
for f in files:
|
42 |
+
f_name = int(f.split(".")[0])
|
43 |
+
with open(save_path + "/" + f) as fp:
|
44 |
+
for line in fp:
|
45 |
+
items = line.strip().split(",")
|
46 |
+
if (len(items) != 5 and f_name != -1):
|
47 |
+
incorrect_files.append(f_name)
|
48 |
+
else:
|
49 |
+
if ((not is_int(items[1].strip()) or not is_int(items[2].strip()) or not is_int(items[3].strip()) or not is_int(items[4].strip())) and f_name != -1):
|
50 |
+
incorrect_files.append(f_name)
|
51 |
+
file_list.append(f_name)
|
52 |
+
file_list = sorted(file_list)
|
53 |
+
incorrect_files = sorted(incorrect_files)
|
54 |
+
return file_list, incorrect_files
|
55 |
+
|
56 |
+
def load_next(rank, img_1, mask_1, img_2, mask_2, img_3, mask_3, img_4, mask_4, example, ids=image_ids, image_prefix=image_prefix, save_path=save_path):
|
57 |
+
file_list, incorrect_files = find_completed_idxs()
|
58 |
+
print(str(file_list) + " " + str(incorrect_files))
|
59 |
+
if (int(example) not in file_list or int(example) in incorrect_files):
|
60 |
+
r = str(image_ids[int(example)]).split(",")[0].split("(")[1] + "," + rank
|
61 |
+
r_fp = open(save_path + "/" + str(int(example)) +".txt", "w")
|
62 |
+
r_fp.write(r + "\n")
|
63 |
+
r_fp.close()
|
64 |
+
file_list, incorrect_files = find_completed_idxs()
|
65 |
+
if (len(incorrect_files) != 0):
|
66 |
+
example = incorrect_files[-1]
|
67 |
+
else:
|
68 |
+
example = file_list[-1] + 1
|
69 |
+
if int(example) == num_rank:
|
70 |
+
rank = "DONE!"
|
71 |
+
example = -1
|
72 |
+
mask_1 = gr.Image(label="Mask", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
73 |
+
img_1 = gr.Image(label="Sample #1", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
74 |
+
mask_2 = gr.Image(label="Mask", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
75 |
+
img_2 = gr.Image(label="Sample #2", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
76 |
+
mask_3 = gr.Image(label="Mask", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
77 |
+
img_3 = gr.Image(label="Sample #3", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
78 |
+
mask_4 = gr.Image(label="Mask", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
79 |
+
img_4 = gr.Image(label="Sample #4", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
80 |
+
else:
|
81 |
+
rank = ""
|
82 |
+
img_1 = gr.Image(label="Sample #1", value=load_img(image_prefix + str(image_ids[int(example)]) + "_synthetic_0.png"), interactive=False)
|
83 |
+
mask_1 = gr.Image(label="Mask", value=load_img(mask_prefix + str(image_ids[int(example)]) + "_mask.png"), interactive=False)
|
84 |
+
img_2 = gr.Image(label="Sample #2", value=load_img(image_prefix+ str(image_ids[int(example)]) + "_synthetic_1.png"), interactive=False)
|
85 |
+
mask_2 = gr.Image(label="Mask", value=load_img(mask_prefix + str(image_ids[int(example)]) + "_mask.png"), interactive=False)
|
86 |
+
img_3 = gr.Image(label="Sample #3", value=load_img(image_prefix + str(image_ids[int(example)]) + "_synthetic_2.png"), interactive=False)
|
87 |
+
mask_3 = gr.Image(label="Mask", value=load_img(mask_prefix + str(image_ids[int(example)]) + "_mask.png"), interactive=False)
|
88 |
+
img_4 = gr.Image(label="Sample #4", value=load_img(image_prefix + str(image_ids[int(example)]) + "_synthetic_3.png"), interactive=False)
|
89 |
+
mask_4 = gr.Image(label="Mask", value=load_img(mask_prefix + str(image_ids[int(example)]) + "_mask.png"), interactive=False)
|
90 |
+
return [rank, img_1, mask_1, img_2, mask_2, img_3, mask_3, img_4, mask_4, example]
|
91 |
+
|
92 |
+
with gr.Blocks() as demo:
|
93 |
+
last_idx = -1
|
94 |
+
example = gr.Number(label="Example #. Click next for #-1 (blank starting page).", value=last_idx, interactive=False)
|
95 |
+
rank = gr.Textbox(label="Rankings (Best to worst, comma-separated, no spaces).")
|
96 |
+
with gr.Column(scale=1):
|
97 |
+
with gr.Row():
|
98 |
+
mask_1 = gr.Image(label="Mask", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
99 |
+
img_1 = gr.Image(label="Sample #1", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
100 |
+
with gr.Row():
|
101 |
+
mask_2 = gr.Image(label="Mask", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
102 |
+
img_2 = gr.Image(label="Sample #2", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
103 |
+
with gr.Row():
|
104 |
+
mask_3 = gr.Image(label="Mask", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
105 |
+
img_3 = gr.Image(label="Sample #3", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
106 |
+
with gr.Row():
|
107 |
+
mask_4 = gr.Image(label="Mask", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
108 |
+
img_4 = gr.Image(label="Sample #4", value=load_img("/deep/u/eprakash/blank.jpg"), interactive=False)
|
109 |
+
next_btn = gr.Button(value="Next")
|
110 |
+
next_btn.click(fn=load_next, inputs=[rank, img_1, mask_1, img_2, mask_2, img_3, mask_3, img_4, mask_4, example], outputs=[rank, img_1, mask_1, img_2, mask_2, img_3, mask_3, img_4, mask_4, example], queue=False)
|
111 |
+
demo.queue()
|
112 |
+
demo.launch(share=True)
|
113 |
+
|
lung_seg_ranks/0.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
'4.5.04.955547.25.3.0.2.364123573012382.7444502808851.4',
|
test_gradio.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import random
|
3 |
+
import time
|
4 |
+
|
5 |
+
fp = open("/deep2/u/eprakash/MedSegDiff/data/ISIC/ISBI2016_ISIC_Part3B_Training_GroundTruth.csv")
|
6 |
+
image_ids = []
|
7 |
+
for line in fp:
|
8 |
+
image_ids.append(line.split(",")[0].split("_")[1])
|
9 |
+
image_ids = image_ids[:700]
|
10 |
+
rankings = []
|
11 |
+
def load_next(rank, img_1, img_2, img_3, img_4, img_5, example, ids=image_ids):
|
12 |
+
if example == len(image_ids):
|
13 |
+
return [None, None, None, None, None, None, None]
|
14 |
+
else:
|
15 |
+
rankings.append(str(image_ids[int(example)-1]) + "," + rank)
|
16 |
+
r_fp = open("ranks/isic_ranks_" + str(int(example) - 1) +".csv", "w")
|
17 |
+
for r in rankings:
|
18 |
+
r_fp.write(r + "\n")
|
19 |
+
r_fp.close()
|
20 |
+
example += 1
|
21 |
+
rank = ""
|
22 |
+
img_1 = gr.Image(label="Sample #1", value="/deep2/u/eprakash/Diffusion-based-Segmentation/isic_synthetic_data/" + str(image_ids[int(example)-1]) + "_synthetic_0.jpg", interactive=False)
|
23 |
+
img_2 = gr.Image(label="Sample #2", value="/deep2/u/eprakash/Diffusion-based-Segmentation/isic_synthetic_data/" + str(image_ids[int(example)-1]) + "_synthetic_1.jpg", interactive=False)
|
24 |
+
img_3 = gr.Image(label="Sample #3", value="/deep2/u/eprakash/Diffusion-based-Segmentation/isic_synthetic_data/" + str(image_ids[int(example)-1]) + "_synthetic_2.jpg", interactive=False)
|
25 |
+
img_4 = gr.Image(label="Sample #4", value="/deep2/u/eprakash/Diffusion-based-Segmentation/isic_synthetic_data/" + str(image_ids[int(example)-1]) + "_synthetic_3.jpg", interactive=False)
|
26 |
+
img_5 = gr.Image(label="Sample #5", value="/deep2/u/eprakash/Diffusion-based-Segmentation/isic_synthetic_data/" + str(image_ids[int(example)-1]) + "_synthetic_4.jpg", interactive=False)
|
27 |
+
return [rank, img_1, img_2, img_3, img_4, img_5, example]
|
28 |
+
|
29 |
+
with gr.Blocks() as demo:
|
30 |
+
example = gr.Number(label="Example #", value=1, interactive=False)
|
31 |
+
rank = gr.Textbox(label="Rankings (Best to worst, comma-separated, no spaces)")
|
32 |
+
with gr.Row():
|
33 |
+
img_1 = gr.Image(label="Sample #1", value="/deep2/u/eprakash/Diffusion-based-Segmentation/isic_synthetic_data/" + str(image_ids[0]) + "_synthetic_0.jpg", interactive=False)
|
34 |
+
img_2 = gr.Image(label="Sample #2", value="/deep2/u/eprakash/Diffusion-based-Segmentation/isic_synthetic_data/" + str(image_ids[0]) + "_synthetic_1.jpg", interactive=False)
|
35 |
+
img_3 = gr.Image(label="Sample #3", value="/deep2/u/eprakash/Diffusion-based-Segmentation/isic_synthetic_data/" + str(image_ids[0]) + "_synthetic_2.jpg", interactive=False)
|
36 |
+
img_4 = gr.Image(label="Sample #4", value="/deep2/u/eprakash/Diffusion-based-Segmentation/isic_synthetic_data/" + str(image_ids[0]) + "_synthetic_3.jpg", interactive=False)
|
37 |
+
img_5 = gr.Image(label="Sample #5", value="/deep2/u/eprakash/Diffusion-based-Segmentation/isic_synthetic_data/" + str(image_ids[0]) + "_synthetic_4.jpg", interactive=False)
|
38 |
+
next_btn = gr.Button(value="Next")
|
39 |
+
next_btn.click(fn=load_next, inputs=[rank, img_1, img_2, img_3, img_4, img_5, example], outputs=[rank, img_1, img_2, img_3, img_4, img_5, example], queue=False)
|
40 |
+
demo.queue()
|
41 |
+
demo.launch(share=True)
|
42 |
+
|
43 |
+
fp.close()
|
test_gradio_2.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import random
|
3 |
+
import time
|
4 |
+
|
5 |
+
fp = open("/deep2/u/eprakash/MedSegDiff/data/ISIC/ISBI2016_ISIC_Part3B_Training_GroundTruth.csv")
|
6 |
+
image_ids = []
|
7 |
+
for line in fp:
|
8 |
+
image_ids.append(line.split(",")[0].split("_")[1])
|
9 |
+
image_ids = image_ids[750:]
|
10 |
+
rankings = []
|
11 |
+
def load_next(rank, img_1, img_2, img_3, img_4, img_5, example, ids=image_ids):
|
12 |
+
if example == len(image_ids):
|
13 |
+
return [None, None, None, None, None, None, None]
|
14 |
+
else:
|
15 |
+
rankings.append(str(image_ids[int(example)-1]) + "," + rank)
|
16 |
+
r_fp = open("ranks_3/isic_ranks_" + str(int(example) - 1) +".csv", "w")
|
17 |
+
for r in rankings:
|
18 |
+
r_fp.write(r + "\n")
|
19 |
+
r_fp.close()
|
20 |
+
example += 1
|
21 |
+
rank = ""
|
22 |
+
img_1 = gr.Image(label="Sample #1", value="/deep2/u/eprakash/Diffusion-based-Segmentation/isic_synthetic_data/" + str(image_ids[int(example)-1]) + "_synthetic_0.jpg", interactive=False)
|
23 |
+
img_2 = gr.Image(label="Sample #2", value="/deep2/u/eprakash/Diffusion-based-Segmentation/isic_synthetic_data/" + str(image_ids[int(example)-1]) + "_synthetic_1.jpg", interactive=False)
|
24 |
+
img_3 = gr.Image(label="Sample #3", value="/deep2/u/eprakash/Diffusion-based-Segmentation/isic_synthetic_data/" + str(image_ids[int(example)-1]) + "_synthetic_2.jpg", interactive=False)
|
25 |
+
img_4 = gr.Image(label="Sample #4", value="/deep2/u/eprakash/Diffusion-based-Segmentation/isic_synthetic_data/" + str(image_ids[int(example)-1]) + "_synthetic_3.jpg", interactive=False)
|
26 |
+
img_5 = gr.Image(label="Sample #5", value="/deep2/u/eprakash/Diffusion-based-Segmentation/isic_synthetic_data/" + str(image_ids[int(example)-1]) + "_synthetic_4.jpg", interactive=False)
|
27 |
+
return [rank, img_1, img_2, img_3, img_4, img_5, example]
|
28 |
+
|
29 |
+
with gr.Blocks() as demo:
|
30 |
+
example = gr.Number(label="Example #", value=1, interactive=False)
|
31 |
+
rank = gr.Textbox(label="Rankings (Best to worst, comma-separated, no spaces)")
|
32 |
+
with gr.Row():
|
33 |
+
img_1 = gr.Image(label="Sample #1", value="/deep2/u/eprakash/Diffusion-based-Segmentation/isic_synthetic_data/" + str(image_ids[0]) + "_synthetic_0.jpg", interactive=False)
|
34 |
+
img_2 = gr.Image(label="Sample #2", value="/deep2/u/eprakash/Diffusion-based-Segmentation/isic_synthetic_data/" + str(image_ids[0]) + "_synthetic_1.jpg", interactive=False)
|
35 |
+
img_3 = gr.Image(label="Sample #3", value="/deep2/u/eprakash/Diffusion-based-Segmentation/isic_synthetic_data/" + str(image_ids[0]) + "_synthetic_2.jpg", interactive=False)
|
36 |
+
img_4 = gr.Image(label="Sample #4", value="/deep2/u/eprakash/Diffusion-based-Segmentation/isic_synthetic_data/" + str(image_ids[0]) + "_synthetic_3.jpg", interactive=False)
|
37 |
+
img_5 = gr.Image(label="Sample #5", value="/deep2/u/eprakash/Diffusion-based-Segmentation/isic_synthetic_data/" + str(image_ids[0]) + "_synthetic_4.jpg", interactive=False)
|
38 |
+
next_btn = gr.Button(value="Next")
|
39 |
+
next_btn.click(fn=load_next, inputs=[rank, img_1, img_2, img_3, img_4, img_5, example], outputs=[rank, img_1, img_2, img_3, img_4, img_5, example], queue=False)
|
40 |
+
demo.queue()
|
41 |
+
demo.launch(share=True)
|
42 |
+
|
43 |
+
fp.close()
|