(hws, image_shape, patch_size=TRAIN_SIZE, sigma=1.0, wtype='gaussian')
| 47 | return [(h, w) for h in hs for w in ws] |
| 48 | |
| 49 | def compute_weight(hws, image_shape, patch_size=TRAIN_SIZE, sigma=1.0, wtype='gaussian'): |
| 50 | patch_num = len(hws) |
| 51 | h, w = torch.meshgrid(torch.arange(patch_size[0]), torch.arange(patch_size[1])) |
| 52 | h, w = h / float(patch_size[0]), w / float(patch_size[1]) |
| 53 | c_h, c_w = 0.5, 0.5 |
| 54 | h, w = h - c_h, w - c_w |
| 55 | weights_hw = (h ** 2 + w ** 2) ** 0.5 / sigma |
| 56 | denorm = 1 / (sigma * math.sqrt(2 * math.pi)) |
| 57 | weights_hw = denorm * torch.exp(-0.5 * (weights_hw) ** 2) |
| 58 | |
| 59 | weights = torch.zeros(1, patch_num, *image_shape) |
| 60 | for idx, (h, w) in enumerate(hws): |
| 61 | weights[:, idx, h:h+patch_size[0], w:w+patch_size[1]] = weights_hw |
| 62 | weights = weights.cuda() |
| 63 | patch_weights = [] |
| 64 | for idx, (h, w) in enumerate(hws): |
| 65 | patch_weights.append(weights[:, idx:idx+1, h:h+patch_size[0], w:w+patch_size[1]]) |
| 66 | |
| 67 | return patch_weights |
| 68 | |
| 69 | def compute_flow(model, image1, image2, weights=None): |
| 70 | print(f"computing flow...") |
nothing calls this directly
no outgoing calls
no test coverage detected