zjjMaiMai / TinyHITNet

HITNet: Hierarchical Iterative Tile Refinement Network for Real-time Stereo Matching
152 stars 21 forks source link

why add 1 in make_cost_volume_v2(4 * x_index - d_range + 1) while make_cost_volume doesn't do so? #22

Open jucic opened 1 year ago

jucic commented 1 year ago

Thanks for your wonderful job. I tried to remove the "+1" inmake_cost_volume_v2, and the predicted disparity of the full image turns out to be a litte smaller than before, and I tried "+2" to "+10", the bigger the added number, the bigger the output disparity, so I wonder if I should add a number when constructing the cost volume, if so, what number should be added?

def make_cost_volume(left, right, max_disp): cost_volume = torch.ones( (left.size(0), left.size(1), max_disp, left.size(2), left.size(3)), dtype=left.dtype, device=left.device, )

cost_volume[:, :, 0, :, :] = left - right
for d in range(1, max_disp):
    cost_volume[:, :, d, :, d:] = left[:, :, :, d:] - right[:, :, :, :-d]

return cost_volume

def make_cost_volume_v2(left, right, max_disp): d_range = torch.arange(max_disp, device=left.device) d_range = d_range.view(1, 1, -1, 1, 1)

x_index = torch.arange(left.size(3), device=left.device)
x_index = x_index.view(1, 1, 1, 1, -1)

x_index = torch.clip(4 * x_index - d_range + 1, 0, right.size(3) - 1).repeat(
    right.size(0), right.size(1), 1, right.size(2), 1
)
right = torch.gather(
    right.unsqueeze(2).repeat(1, 1, max_disp, 1, 1), dim=-1, index=x_index
)

return left.unsqueeze(2) - right