| 255 | |
| 256 | |
| 257 | class InverseCDFRaySampling(Function): |
| 258 | @staticmethod |
| 259 | def forward( |
| 260 | ctx, |
| 261 | pts_idx, |
| 262 | min_depth, |
| 263 | max_depth, |
| 264 | probs, |
| 265 | steps, |
| 266 | fixed_step_size=-1, |
| 267 | deterministic=False, |
| 268 | ): |
| 269 | G, N, P = int(np.ceil(pts_idx.size(0) / 2048)), pts_idx.size(0), pts_idx.size(1) |
| 270 | # if G == 0: |
| 271 | # G = 200 |
| 272 | H = int(np.ceil(N / G)) * G |
| 273 | |
| 274 | if H > N: |
| 275 | pts_idx = torch.cat([pts_idx, pts_idx[:1].expand(H - N, P)], 0) |
| 276 | min_depth = torch.cat( |
| 277 | [min_depth, min_depth[:1].expand(H - N, P)], 0) |
| 278 | max_depth = torch.cat( |
| 279 | [max_depth, max_depth[:1].expand(H - N, P)], 0) |
| 280 | probs = torch.cat([probs, probs[:1].expand(H - N, P)], 0) |
| 281 | steps = torch.cat([steps, steps[:1].expand(H - N)], 0) |
| 282 | |
| 283 | # print(G, P, np.ceil(N / G), N, H, pts_idx.shape, min_depth.device) |
| 284 | pts_idx = pts_idx.reshape(G, -1, P) |
| 285 | min_depth = min_depth.reshape(G, -1, P) |
| 286 | max_depth = max_depth.reshape(G, -1, P) |
| 287 | probs = probs.reshape(G, -1, P) |
| 288 | steps = steps.reshape(G, -1) |
| 289 | |
| 290 | # pre-generate noise |
| 291 | max_steps = steps.ceil().long().max() + P |
| 292 | noise = min_depth.new_zeros(*min_depth.size()[:-1], max_steps) |
| 293 | if deterministic: |
| 294 | noise += 0.5 |
| 295 | else: |
| 296 | noise = noise.uniform_().clamp(min=0.001, max=0.999) # in case |
| 297 | |
| 298 | # call cuda function |
| 299 | # chunk_size = 4 * G # to avoid oom? |
| 300 | results = [ |
| 301 | _ext.inverse_cdf_sampling( |
| 302 | pts_idx.contiguous(), |
| 303 | min_depth.float().contiguous(), |
| 304 | max_depth.float().contiguous(), |
| 305 | noise.float().contiguous(), |
| 306 | probs.float().contiguous(), |
| 307 | steps.float().contiguous(), |
| 308 | fixed_step_size, |
| 309 | ) |
| 310 | ] |
| 311 | # |
| 312 | # # call cuda function |
| 313 | # chunk_size = 4 * G # to avoid oom? |
| 314 | # results = [ |
nothing calls this directly
no outgoing calls
no test coverage detected