Skip to content

Commit 8d26f6a

Browse files
committed
update visualization
1 parent 02891c1 commit 8d26f6a

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

visualize_flow.py

+22-17
Original file line numberDiff line numberDiff line change
@@ -71,28 +71,33 @@ def compute_flow(model, image1, image2, weights=None):
7171

7272
image_size = image1.shape[1:]
7373

74+
image1, image2 = image1[None].cuda(), image2[None].cuda()
75+
7476
hws = compute_grid_indices(image_size)
75-
if weights is None:
76-
weights = compute_weight(hws, image_size, sigma=0.05)
77+
if weights is None: # no tile
78+
padder = InputPadder(image1.shape)
79+
image1, image2 = padder.pad(image1, image2)
7780

78-
image1, image2 = image1[None].cuda(), image2[None].cuda()
81+
flow_pre, _ = model(image1, image2)
7982

80-
flows = 0
81-
flow_count = 0
83+
flow_pre = padder.unpad(flow_pre)
84+
flow = flow_pre[0].permute(1, 2, 0).cpu().numpy()
85+
else: # tile
86+
flows = 0
87+
flow_count = 0
8288

83-
for idx, (h, w) in enumerate(hws):
84-
image1_tile = image1[:, :, h:h+TRAIN_SIZE[0], w:w+TRAIN_SIZE[1]]
85-
image2_tile = image2[:, :, h:h+TRAIN_SIZE[0], w:w+TRAIN_SIZE[1]]
86-
flow_pre, _ = model(image1_tile, image2_tile)
87-
padding = (w, image_size[1]-w-TRAIN_SIZE[1], h, image_size[0]-h-TRAIN_SIZE[0], 0, 0)
88-
flows += F.pad(flow_pre * weights[idx], padding)
89-
# flow_count += F.pad(weights, padding)
90-
flow_count += F.pad(weights[idx], padding)
89+
for idx, (h, w) in enumerate(hws):
90+
image1_tile = image1[:, :, h:h+TRAIN_SIZE[0], w:w+TRAIN_SIZE[1]]
91+
image2_tile = image2[:, :, h:h+TRAIN_SIZE[0], w:w+TRAIN_SIZE[1]]
92+
flow_pre, _ = model(image1_tile, image2_tile)
93+
padding = (w, image_size[1]-w-TRAIN_SIZE[1], h, image_size[0]-h-TRAIN_SIZE[0], 0, 0)
94+
flows += F.pad(flow_pre * weights[idx], padding)
95+
flow_count += F.pad(weights[idx], padding)
9196

92-
flow_pre = flows / flow_count
93-
flow = flow_pre[0].permute(1, 2, 0).cpu().numpy()
97+
flow_pre = flows / flow_count
98+
flow = flow_pre[0].permute(1, 2, 0).cpu().numpy()
9499

95-
return flow, weights
100+
return flow
96101

97102
def compute_adaptive_image_size(image_size):
98103
target_size = TRAIN_SIZE
@@ -153,7 +158,7 @@ def visualize_flow(root_dir, viz_root_dir, model, img_pairs, keep_size):
153158
print(f"processing {fn1}, {fn2}...")
154159

155160
image1, image2, viz_fn = prepare_image(root_dir, viz_root_dir, fn1, fn2, keep_size)
156-
flow, weights = compute_flow(model, image1, image2, weights)
161+
flow = compute_flow(model, image1, image2, weights)
157162
flow_img = flow_viz.flow_to_image(flow)
158163
cv2.imwrite(viz_fn, flow_img[:, :, [2,1,0]])
159164

0 commit comments

Comments
 (0)