MCPcopy Index your code
hub / github.com/drinkingcoder/FlowFormer-Official / compute_weight

Function compute_weight

evaluate_FlowFormer_tile.py:68–86  ·  view source on GitHub ↗
(hws, image_shape, patch_size=TRAIN_SIZE, sigma=1.0, wtype='gaussian')

Source from the content-addressed store, hash-verified

66
67import math
68def 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()
89def create_sintel_submission(model, output_path='sintel_submission_multi8_768', sigma=0.05):

Callers 4

create_sintel_submissionFunction · 0.70
create_kitti_submissionFunction · 0.70
validate_kittiFunction · 0.70
validate_sintelFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected