tokenid commited on
Commit
0e18ab2
1 Parent(s): c12c627

more examples & fix scales

Browse files
app.py CHANGED
@@ -69,13 +69,13 @@ def group_recenter(images, ratio=1.5, mask_thres=127, bkg_color=[255, 255, 255,
69
  y0, y1 = yy.min(), yy.max()
70
  x0, x1 = xx.min(), xx.max()
71
 
72
- ws.append(x1 - x0)
73
- hs.append(y1 - y0)
74
 
75
  sz_w = np.max(ws)
76
  sz_h = np.max(hs)
77
 
78
- sz = int( max(ratio*sz_w, ratio*sz_h) )
79
 
80
  out_rgbs = []
81
 
@@ -93,16 +93,14 @@ def group_recenter(images, ratio=1.5, mask_thres=127, bkg_color=[255, 255, 255,
93
  cy = (y0 + y1) // 2
94
  cx = (x0 + x1) // 2
95
 
96
- y0 = cy - int(np.floor(sz / 2))
97
- y1 = cy + int(np.ceil(sz / 2))
98
- x0 = cx - int(np.floor(sz / 2))
99
- x1 = cx + int(np.ceil(sz / 2))
100
  out = rgba[ max(y0, 0) : min(y1, height) , max(x0, 0) : min(x1, width), : ].copy()
101
  pads = [(max(0-y0, 0), max(y1-height, 0)), (max(0-x0, 0), max(x1-width, 0)), (0, 0)]
102
  out = np.pad(out, pads, mode='constant', constant_values=0)
103
 
104
- assert(out.shape[:2] == (sz, sz))
105
-
106
  out[:, :, :3] = out[:, :, :3] * (out[..., 3:]/255.) + np.array(bkg_color)[None, None, :3] * (1-out[..., 3:]/255.)
107
  out[:, :, -1] = bkg_color[-1]
108
 
@@ -148,7 +146,7 @@ def run_pose_exploration(cam_vis, image1, image2, probe_bsz, adj_bsz, adj_iters,
148
  cam_vis.set_images([np.asarray(image1, dtype=np.uint8), np.asarray(image2, dtype=np.uint8)])
149
 
150
  image1 = image_to_tensor(image1).to(_device_)
151
- image2 = image_to_tensor(image2).to(_device_)
152
 
153
  images = [image1, image2]
154
 
@@ -158,29 +156,33 @@ def run_pose_exploration(cam_vis, image1, image2, probe_bsz, adj_bsz, adj_iters,
158
  matcher_ckpt_path=_matcher_ckpt_path_
159
  )
160
 
161
- noise = np.random.randn(probe_bsz, 4, 32, 32)
162
-
163
- result_poses, aux_data = estimate_poses(
164
- _model_, images,
165
- seed_cand_num=8,
166
- explore_type='triangular',
167
- refine_type='triangular',
168
- probe_ts_range=[0.2, 0.21],
169
- ts_range=[0.2, 0.21],
170
- probe_bsz=probe_bsz,
171
- adjust_factor=10.0,
172
- adjust_iters=adj_iters,
173
- adjust_bsz=adj_bsz,
174
- refine_factor=1.0,
175
- refine_iters=0,
176
- refine_bsz=4,
177
- noise=noise,
178
- elevs=elevs,
179
- elev_ranges=elev_ranges
180
- )
 
 
 
 
 
 
181
 
182
- theta, azimuth, radius = result_poses[0]
183
- anchor_polar = aux_data['elev'][0]
184
  if anchor_polar is None:
185
  anchor_polar = np.pi/2
186
 
@@ -245,8 +247,8 @@ _HEADER_ = '''
245
  '''
246
 
247
  _FOOTER_ = '''
248
- - Project Page: [https://xt4d.github.io/id-pose-web/](https://xt4d.github.io/id-pose-web/)
249
- - Github: [https://github.com/xt4d/id-pose](https://github.com/xt4d/id-pose)
250
  '''
251
 
252
  _CITE_ = r"""
@@ -321,37 +323,43 @@ def run_demo():
321
  ['data/gradio_demo/duck_0.png', 'data/gradio_demo/duck_1.png'],
322
  ['data/gradio_demo/chair_0.png', 'data/gradio_demo/chair_1.png'],
323
  ['data/gradio_demo/foosball_0.png', 'data/gradio_demo/foosball_1.png'],
 
 
324
  ],
325
  inputs=[input_image1, input_image2],
326
- label='Examples (Self-captured)',
327
  cache_examples=False,
328
- examples_per_page=3
329
  )
330
 
331
  with gr.Column(min_width=200):
332
  gr.Examples(
333
  examples = [
334
- ['data/gradio_demo/bunny_0.png', 'data/gradio_demo/bunny_1.png'],
335
- ['data/gradio_demo/bus_0.png', 'data/gradio_demo/bus_1.png'],
336
- ['data/gradio_demo/circo_0.png', 'data/gradio_demo/circo_1.png'],
 
 
337
  ],
338
  inputs=[input_image1, input_image2],
339
- label='Examples (Images from NAVI)',
340
  cache_examples=False,
341
- examples_per_page=3
342
  )
343
 
344
  with gr.Column(min_width=200):
345
  gr.Examples(
346
  examples = [
347
  ['data/gradio_demo/status_0.png', 'data/gradio_demo/status_1.png'],
348
- ['data/gradio_demo/bag_0.png', 'data/gradio_demo/bag_1.png'],
349
  ['data/gradio_demo/cat_0.png', 'data/gradio_demo/cat_1.png'],
 
 
 
350
  ],
351
  inputs=[input_image1, input_image2],
352
  label='Examples (Generated)',
353
  cache_examples=False,
354
- examples_per_page=3
355
  )
356
 
357
  cam_vis = CameraVisualizer([np.eye(4), np.eye(4)], ['Image 1', 'Image 2'], ['red', 'blue'])
 
69
  y0, y1 = yy.min(), yy.max()
70
  x0, x1 = xx.min(), xx.max()
71
 
72
+ ws.append(float(x1 - x0) / img.shape[0])
73
+ hs.append(float(y1 - y0) / img.shape[1])
74
 
75
  sz_w = np.max(ws)
76
  sz_h = np.max(hs)
77
 
78
+ sz = max(ratio*sz_w, ratio*sz_h)
79
 
80
  out_rgbs = []
81
 
 
93
  cy = (y0 + y1) // 2
94
  cx = (x0 + x1) // 2
95
 
96
+ y0 = cy - int(np.floor(sz * rgba.shape[0] / 2))
97
+ y1 = cy + int(np.ceil(sz * rgba.shape[0] / 2))
98
+ x0 = cx - int(np.floor(sz * rgba.shape[1] / 2))
99
+ x1 = cx + int(np.ceil(sz * rgba.shape[1] / 2))
100
  out = rgba[ max(y0, 0) : min(y1, height) , max(x0, 0) : min(x1, width), : ].copy()
101
  pads = [(max(0-y0, 0), max(y1-height, 0)), (max(0-x0, 0), max(x1-width, 0)), (0, 0)]
102
  out = np.pad(out, pads, mode='constant', constant_values=0)
103
 
 
 
104
  out[:, :, :3] = out[:, :, :3] * (out[..., 3:]/255.) + np.array(bkg_color)[None, None, :3] * (1-out[..., 3:]/255.)
105
  out[:, :, -1] = bkg_color[-1]
106
 
 
146
  cam_vis.set_images([np.asarray(image1, dtype=np.uint8), np.asarray(image2, dtype=np.uint8)])
147
 
148
  image1 = image_to_tensor(image1).to(_device_)
149
+ image2 = image_to_tensor(image2).to(_device_)
150
 
151
  images = [image1, image2]
152
 
 
156
  matcher_ckpt_path=_matcher_ckpt_path_
157
  )
158
 
159
+ anchor_polar = elevs[0]
160
+
161
+ if torch.mean(torch.abs(image1 - image2)) < 0.005:
162
+ theta = azimuth = radius = 0
163
+ print('Identical images found!')
164
+ else:
165
+ noise = np.random.randn(probe_bsz, 4, 32, 32)
166
+ result_poses, aux_data = estimate_poses(
167
+ _model_, images,
168
+ seed_cand_num=8,
169
+ explore_type='triangular',
170
+ refine_type='triangular',
171
+ probe_ts_range=[0.2, 0.21],
172
+ ts_range=[0.2, 0.21],
173
+ probe_bsz=probe_bsz,
174
+ adjust_factor=10.0,
175
+ adjust_iters=adj_iters,
176
+ adjust_bsz=adj_bsz,
177
+ refine_factor=1.0,
178
+ refine_iters=0,
179
+ refine_bsz=4,
180
+ noise=noise,
181
+ elevs=elevs,
182
+ elev_ranges=elev_ranges
183
+ )
184
+ theta, azimuth, radius = result_poses[0]
185
 
 
 
186
  if anchor_polar is None:
187
  anchor_polar = np.pi/2
188
 
 
247
  '''
248
 
249
  _FOOTER_ = '''
250
+ [Project Page](https://xt4d.github.io/id-pose-web/) | ⭐ [Github](https://github.com/xt4d/id-pose) ⭐ [![GitHub Stars](https://img.shields.io/github/stars/xt4d/id-pose?style=social)](https://github.com/xt4d/id-pose)
251
+ ---
252
  '''
253
 
254
  _CITE_ = r"""
 
323
  ['data/gradio_demo/duck_0.png', 'data/gradio_demo/duck_1.png'],
324
  ['data/gradio_demo/chair_0.png', 'data/gradio_demo/chair_1.png'],
325
  ['data/gradio_demo/foosball_0.png', 'data/gradio_demo/foosball_1.png'],
326
+ ['data/gradio_demo/bunny_0.png', 'data/gradio_demo/bunny_1.png'],
327
+ ['data/gradio_demo/circo_0.png', 'data/gradio_demo/circo_1.png'],
328
  ],
329
  inputs=[input_image1, input_image2],
330
+ label='Examples (Captured)',
331
  cache_examples=False,
332
+ examples_per_page=5
333
  )
334
 
335
  with gr.Column(min_width=200):
336
  gr.Examples(
337
  examples = [
338
+ ['data/gradio_demo/arc_0.png', 'data/gradio_demo/arc_1.png'],
339
+ ['data/gradio_demo/husky_0.png', 'data/gradio_demo/husky_1.png'],
340
+ ['data/gradio_demo/cybertruck_0.png', 'data/gradio_demo/cybertruck_1.png'],
341
+ ['data/gradio_demo/plane_0.png', 'data/gradio_demo/plane_1.png'],
342
+ ['data/gradio_demo/christ_0.png', 'data/gradio_demo/christ_1.png'],
343
  ],
344
  inputs=[input_image1, input_image2],
345
+ label='Examples (Internet)',
346
  cache_examples=False,
347
+ examples_per_page=5
348
  )
349
 
350
  with gr.Column(min_width=200):
351
  gr.Examples(
352
  examples = [
353
  ['data/gradio_demo/status_0.png', 'data/gradio_demo/status_1.png'],
 
354
  ['data/gradio_demo/cat_0.png', 'data/gradio_demo/cat_1.png'],
355
+ ['data/gradio_demo/ferrari_0.png', 'data/gradio_demo/ferrari_1.png'],
356
+ ['data/gradio_demo/elon_0.png', 'data/gradio_demo/elon_1.png'],
357
+ ['data/gradio_demo/ride_horse_0.png', 'data/gradio_demo/ride_horse_1.png'],
358
  ],
359
  inputs=[input_image1, input_image2],
360
  label='Examples (Generated)',
361
  cache_examples=False,
362
+ examples_per_page=5
363
  )
364
 
365
  cam_vis = CameraVisualizer([np.eye(4), np.eye(4)], ['Image 1', 'Image 2'], ['red', 'blue'])
data/gradio_demo/arc_0.png ADDED
data/gradio_demo/arc_1.png ADDED
data/gradio_demo/christ_0.png ADDED
data/gradio_demo/christ_1.png ADDED
data/gradio_demo/cybertruck_0.png ADDED
data/gradio_demo/cybertruck_1.png ADDED
data/gradio_demo/elon_0.png ADDED
data/gradio_demo/elon_1.png ADDED
data/gradio_demo/ferrari_0.png ADDED
data/gradio_demo/ferrari_1.png ADDED
data/gradio_demo/husky_0.png ADDED
data/gradio_demo/husky_1.png ADDED
data/gradio_demo/plane_0.png ADDED
data/gradio_demo/plane_1.png ADDED
data/gradio_demo/ride_horse_0.png ADDED
data/gradio_demo/ride_horse_1.png ADDED