text
stringlengths 1
93.6k
|
---|
h_shift = 1
|
w_shift = 1
|
p2d = (w_shift, w_shift, h_shift, h_shift)
|
feat_pd = F.pad(input, p2d, mode='constant', value=0)
|
gt_frm_top_left = F.interpolate(feat_pd[:, :, :-2 * h_shift, :-2 * w_shift], size=(h * up_h, w * up_w),mode='nearest')
|
feat_sum = gt_frm_top_left * prob.narrow(1,0,1)
|
top = F.interpolate(feat_pd[:, :, :-2 * h_shift, w_shift:-w_shift], size=(h * up_h, w * up_w), mode='nearest')
|
feat_sum += top * prob.narrow(1, 1, 1)
|
top_right = F.interpolate(feat_pd[:, :, :-2 * h_shift, 2 * w_shift:], size=(h * up_h, w * up_w), mode='nearest')
|
feat_sum += top_right * prob.narrow(1,2,1)
|
left = F.interpolate(feat_pd[:, :, h_shift:-w_shift, :-2 * w_shift], size=(h * up_h, w * up_w), mode='nearest')
|
feat_sum += left * prob.narrow(1, 3, 1)
|
center = F.interpolate(input, (h * up_h, w * up_w), mode='nearest')
|
feat_sum += center * prob.narrow(1, 4, 1)
|
right = F.interpolate(feat_pd[:, :, h_shift:-w_shift, 2 * w_shift:], size=(h * up_h, w * up_w), mode='nearest')
|
feat_sum += right * prob.narrow(1, 5, 1)
|
bottom_left = F.interpolate(feat_pd[:, :, 2 * h_shift:, :-2 * w_shift], size=(h * up_h, w * up_w), mode='nearest')
|
feat_sum += bottom_left * prob.narrow(1, 6, 1)
|
bottom = F.interpolate(feat_pd[:, :, 2 * h_shift:, w_shift:-w_shift], size=(h * up_h, w * up_w), mode='nearest')
|
feat_sum += bottom * prob.narrow(1, 7, 1)
|
bottom_right = F.interpolate(feat_pd[:, :, 2 * h_shift:, 2 * w_shift:], size=(h * up_h, w * up_w), mode='nearest')
|
feat_sum += bottom_right * prob.narrow(1, 8, 1)
|
return feat_sum
|
# ================= - spixel related -=============
|
def assign2uint8(assign):
|
#red up, green mid, blue down, for debug only
|
b,c,h,w = assign.shape
|
red = torch.cat([torch.ones(size=assign.shape), torch.zeros(size=[b,2,h,w])],dim=1).cuda()
|
green = torch.cat([ torch.zeros(size=[b,1,h,w]),
|
torch.ones(size=assign.shape),
|
torch.zeros(size=[b,1,h,w])],dim=1).cuda()
|
blue = torch.cat([torch.zeros(size=[b,2,h,w]),
|
torch.ones(size=assign.shape)],dim=1).cuda()
|
black = torch.zeros(size=[b,3,h,w]).cuda()
|
white = torch.ones(size=[b,3,h,w]).cuda()
|
# up probablity
|
mat_vis = torch.where(assign.type(torch.float) < 0. , white, black)
|
mat_vis = torch.where(assign.type(torch.float) >= 0. , red* (assign.type(torch.float)+1)/3, mat_vis)
|
mat_vis = torch.where(assign.type(torch.float) >= 3., green*(assign.type(torch.float)-2)/3, mat_vis)
|
mat_vis = torch.where(assign.type(torch.float) >= 6., blue * (assign.type(torch.float) - 5.) / 3, mat_vis)
|
return (mat_vis * 255.).type(torch.uint8)
|
def val2uint8(mat,maxVal):
|
maxVal_mat = torch.ones(mat.shape).cuda() * maxVal
|
mat_vis = torch.where(mat > maxVal_mat, maxVal_mat, mat)
|
return (mat_vis * 255. / maxVal).type(torch.uint8)
|
def update_spixl_map (spixl_map_idx_in, assig_map_in):
|
assig_map = assig_map_in.clone()
|
b,_,h,w = assig_map.shape
|
_, _, id_h, id_w = spixl_map_idx_in.shape
|
if (id_h == h) and (id_w == w):
|
spixl_map_idx = spixl_map_idx_in
|
else:
|
spixl_map_idx = F.interpolate(spixl_map_idx_in, size=(h,w), mode='nearest')
|
assig_max,_ = torch.max(assig_map, dim=1, keepdim= True)
|
assignment_ = torch.where(assig_map == assig_max, torch.ones(assig_map.shape).cuda(),torch.zeros(assig_map.shape).cuda())
|
new_spixl_map_ = spixl_map_idx * assignment_ # winner take all
|
new_spixl_map = torch.sum(new_spixl_map_,dim=1,keepdim=True).type(torch.int)
|
return new_spixl_map
|
def get_spixel_image(given_img, spix_index, n_spixels = 600, b_enforce_connect = False):
|
if not isinstance(given_img, np.ndarray):
|
given_img_np_ = given_img.detach().cpu().numpy().transpose(1,2,0)
|
else: # for cvt lab to rgb case
|
given_img_np_ = given_img
|
if not isinstance(spix_index, np.ndarray):
|
spix_index_np = spix_index.detach().cpu().numpy().transpose(0,1)
|
else:
|
spix_index_np = spix_index
|
h, w = spix_index_np.shape
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.