(hws, image_shape, patch_size=TRAIN_SIZE, sigma=1.0, wtype='gaussian')
| 66 | |
| 67 | import math |
| 68 | def compute_weight(hws, image_shape, patch_size=TRAIN_SIZE, sigma=1.0, wtype='gaussian'): |
| 69 | patch_num = len(hws) |
| 70 | h, w = torch.meshgrid(torch.arange(patch_size[0]), torch.arange(patch_size[1])) |
| 71 | h, w = h / float(patch_size[0]), w / float(patch_size[1]) |
| 72 | c_h, c_w = 0.5, 0.5 |
| 73 | h, w = h - c_h, w - c_w |
| 74 | weights_hw = (h ** 2 + w ** 2) ** 0.5 / sigma |
| 75 | denorm = 1 / (sigma * math.sqrt(2 * math.pi)) |
| 76 | weights_hw = denorm * torch.exp(-0.5 * (weights_hw) ** 2) |
| 77 | |
| 78 | weights = torch.zeros(1, patch_num, *image_shape) |
| 79 | for idx, (h, w) in enumerate(hws): |
| 80 | weights[:, idx, h:h+patch_size[0], w:w+patch_size[1]] = weights_hw |
| 81 | weights = weights.cuda() |
| 82 | patch_weights = [] |
| 83 | for idx, (h, w) in enumerate(hws): |
| 84 | patch_weights.append(weights[:, idx:idx+1, h:h+patch_size[0], w:w+patch_size[1]]) |
| 85 | |
| 86 | return patch_weights |
| 87 | |
| 88 | @torch.no_grad() |
| 89 | def create_sintel_submission(model, output_path='sintel_submission_multi8_768', sigma=0.05): |
no outgoing calls
no test coverage detected