pytorch~改变tensor的值(对mask进行0\1化操作)
new_mask_image = torch.zeros([inst_map.shape[0],inst_map.shape[1],inst_map.shape[2],inst_map.shape[3]], dtype=torch.float32,device=inst_map.device) for i in range(inst_map.shape[0]): f_mask = inst_map [i,:,:,:] zero = torch.zeros_like(f_mask) one = torch.ones_like(f_mask) f_mask= torch.where(f_mask> -1.0, one, zero) new_mask_image[i,:,:,:] = f_mask