nanom commited on
Commit
fbe3694
·
1 Parent(s): 8c850aa

Add segmented image

Browse files
Files changed (2) hide show
  1. app.py +6 -3
  2. utils.py +11 -10
app.py CHANGED
@@ -29,15 +29,18 @@ with demo:
29
  btn_next = gr.Button("Get Next Sample")
30
 
31
  with gr.Column():
32
- with gr.Row():
33
- info = gr.Text(label="Sample Info")
34
  with gr.Row():
35
  img = gr.Image(label="Sample", type="numpy")
 
 
 
 
 
36
 
37
  btn_next.click(
38
  fn=sample.explorateSamples,
39
  inputs=[username,predictions,category,model,split,next_idx_sample],
40
- outputs=[next_idx_sample, progress, img, info])
41
 
42
  demo.queue(concurrency_count=10)
43
  demo.launch(debug=False)
 
29
  btn_next = gr.Button("Get Next Sample")
30
 
31
  with gr.Column():
 
 
32
  with gr.Row():
33
  img = gr.Image(label="Sample", type="numpy")
34
+ with gr.Row():
35
+ with gr.Column():
36
+ info = gr.Text(label="Info")
37
+ with gr.Column():
38
+ img_seg = gr.Image(label="Segmentation", type="numpy")
39
 
40
  btn_next.click(
41
  fn=sample.explorateSamples,
42
  inputs=[username,predictions,category,model,split,next_idx_sample],
43
+ outputs=[next_idx_sample, progress, img, info, img_seg])
44
 
45
  demo.queue(concurrency_count=10)
46
  demo.launch(debug=False)
utils.py CHANGED
@@ -22,8 +22,8 @@ class SampleClass:
22
  img = np.array(pill_img)
23
  return img
24
 
25
- def __loadPredictions(self, split, model):
26
 
 
27
  assert(split in ['test','val'])
28
  assert(model in ['baseline','extended'])
29
 
@@ -56,7 +56,6 @@ class SampleClass:
56
  pos_tags = sample['pos_tags'].values[0]
57
  plural_tks = sample['plural_tks'].values[0]
58
 
59
-
60
  cat_intrinsic = sample['intrinsic'].values[0]
61
  cat_spatial = sample['spatial'].values[0]
62
  cat_ordinal = sample['ordinal'].values[0]
@@ -67,10 +66,6 @@ class SampleClass:
67
  ('ordinal',cat_ordinal),
68
  ('relational',cat_relational),
69
  ('plural',cat_plural)]
70
-
71
-
72
- img_path = "saiapr_tc-12"+sample['file_path'].values[0].split("saiapr_tc-12")[1]
73
- # print(img_path)
74
 
75
  hit = sample['hit'].values[0]
76
  hit_o = sample['hit_other'].values[0]
@@ -92,7 +87,11 @@ class SampleClass:
92
  x1_pred_o,y1_pred_o,x2_pred_o,y2_pred_o = bp_o_bbox
93
  # x1_pred_o,y1_pred_o,x2_pred_o,y2_pred_o = tuple(map(float,bp_o_bbox[1:-1].split(",")))
94
 
95
- # Plot
 
 
 
 
96
  fig, ax = plt.subplots(1)
97
  ax.imshow(self.__get(img_path), interpolation='bilinear')
98
 
@@ -128,7 +127,9 @@ class SampleClass:
128
  data = np.frombuffer(fig.canvas.tostring_rgb(), dtype=np.uint8)
129
  w, h = fig.canvas.get_width_height()
130
  img = data.reshape((int(h), int(w), -1))
131
- return info, img
 
 
132
 
133
  def explorateSamples(self,
134
  username,
@@ -160,8 +161,8 @@ class SampleClass:
160
 
161
  next_idx_sample = user_ids[username][ min(id_+1, len(user_ids[username])-1) ]
162
  progress = {f"{id_}/{len(user_ids[username])-1}":id_/(len(user_ids[username])-1)}
163
- info, img = self.__getSample(user_ids[username][id_])
164
  info = "".join([str(k)+":\t"+str(v)+"\n" for k,v in list(info.items())[1:]]).strip()
165
 
166
- return (gr.Number.update(value=next_idx_sample),progress,img,info)
167
 
 
22
  img = np.array(pill_img)
23
  return img
24
 
 
25
 
26
+ def __loadPredictions(self, split, model):
27
  assert(split in ['test','val'])
28
  assert(model in ['baseline','extended'])
29
 
 
56
  pos_tags = sample['pos_tags'].values[0]
57
  plural_tks = sample['plural_tks'].values[0]
58
 
 
59
  cat_intrinsic = sample['intrinsic'].values[0]
60
  cat_spatial = sample['spatial'].values[0]
61
  cat_ordinal = sample['ordinal'].values[0]
 
66
  ('ordinal',cat_ordinal),
67
  ('relational',cat_relational),
68
  ('plural',cat_plural)]
 
 
 
 
69
 
70
  hit = sample['hit'].values[0]
71
  hit_o = sample['hit_other'].values[0]
 
87
  x1_pred_o,y1_pred_o,x2_pred_o,y2_pred_o = bp_o_bbox
88
  # x1_pred_o,y1_pred_o,x2_pred_o,y2_pred_o = tuple(map(float,bp_o_bbox[1:-1].split(",")))
89
 
90
+ # Create Fig with predictions
91
+ img_path = "saiapr_tc-12"+sample['file_path'].values[0].split("saiapr_tc-12")[1]
92
+ img_seg_path = img_path.replace("images","segmented_images")
93
+
94
+
95
  fig, ax = plt.subplots(1)
96
  ax.imshow(self.__get(img_path), interpolation='bilinear')
97
 
 
127
  data = np.frombuffer(fig.canvas.tostring_rgb(), dtype=np.uint8)
128
  w, h = fig.canvas.get_width_height()
129
  img = data.reshape((int(h), int(w), -1))
130
+
131
+
132
+ return info, img, self.__get(img_seg_path)
133
 
134
  def explorateSamples(self,
135
  username,
 
161
 
162
  next_idx_sample = user_ids[username][ min(id_+1, len(user_ids[username])-1) ]
163
  progress = {f"{id_}/{len(user_ids[username])-1}":id_/(len(user_ids[username])-1)}
164
+ info, img, img_seg = self.__getSample(user_ids[username][id_])
165
  info = "".join([str(k)+":\t"+str(v)+"\n" for k,v in list(info.items())[1:]]).strip()
166
 
167
+ return (gr.Number.update(value=next_idx_sample),progress,img,info,img_seg)
168