(flow)
| 108 | return imgw |
| 109 | |
| 110 | def forward_interpolate(flow): |
| 111 | flow = flow.detach().cpu().numpy() |
| 112 | dx, dy = flow[0], flow[1] |
| 113 | |
| 114 | ht, wd = dx.shape |
| 115 | x0, y0 = np.meshgrid(np.arange(wd), np.arange(ht)) |
| 116 | |
| 117 | x1 = x0 + dx |
| 118 | y1 = y0 + dy |
| 119 | |
| 120 | x1 = x1.reshape(-1) |
| 121 | y1 = y1.reshape(-1) |
| 122 | dx = dx.reshape(-1) |
| 123 | dy = dy.reshape(-1) |
| 124 | |
| 125 | valid = (x1 > 0) & (x1 < wd) & (y1 > 0) & (y1 < ht) |
| 126 | x1 = x1[valid] |
| 127 | y1 = y1[valid] |
| 128 | dx = dx[valid] |
| 129 | dy = dy[valid] |
| 130 | |
| 131 | flow_x = interpolate.griddata( |
| 132 | (x1, y1), dx, (x0, y0), method='nearest', fill_value=0) |
| 133 | |
| 134 | flow_y = interpolate.griddata( |
| 135 | (x1, y1), dy, (x0, y0), method='nearest', fill_value=0) |
| 136 | |
| 137 | flow = np.stack([flow_x, flow_y], axis=0) |
| 138 | return torch.from_numpy(flow).float() |
| 139 | |
| 140 | |
| 141 | def bilinear_sampler(img, coords, mode='bilinear', mask=False): |
nothing calls this directly
no outgoing calls
no test coverage detected