def _get_salency_map(self, item, use_cuda=False): cfile = self.data[item][:-4] + '_gt.npy' if item >= 0: if self.cache_gt and os.path.isfile(cfile): target_map = th.from_numpy(np.load(cfile)).float() assert target_map.size() == (1, self.frame_h, self.frame_w) return th.from_numpy(np.load(cfile)).float() target = np.zeros((self.frame_h, self.frame_w)) for x_norm, y_norm in self.target[item]: x, y = min(int(x_norm * self.frame_w + 0.5), self.frame_w - 1), min(int(y_norm * self.frame_h + 0.5), self.frame_h - 1) target[y, x] = 10 kernel = self._gen_gaussian_kernel() # print(kernel.max()) if use_cuda: target_map = spherical_conv( th.from_numpy( target.reshape(1, 1, *target.shape) ).cuda(), th.from_numpy(kernel.reshape(1, 1, *kernel.shape)).cuda(), kernel_rad=self.kernel_rad, padding_mode=0 ).view(1, self.frame_h, self.frame_w) else: target_map = spherical_conv( th.from_numpy( target.reshape(1, 1, *target.shape) ), th.from_numpy(kernel.reshape(1, 1, *kernel.shape)), kernel_rad=self.kernel_rad, padding_mode=0 ).view(1, self.frame_h, self.frame_w) if item >= 0 and self.cache_gt: np.save(cfile, target_map.data.cpu().numpy() / len(self.target[item])) return target_map.data.float() / len(self.target[item])
def _get_salency_map(self, item, use_cuda=False): assert item == -1 target = np.zeros((self.frame_h, self.frame_w)) for x_norm, y_norm in self.target[item]: x, y = min(int(x_norm * self.frame_w + 0.5), self.frame_w - 1), min(int(y_norm * self.frame_h + 0.5), self.frame_h - 1) target[y, x] = 10 kernel = self._gen_gaussian_kernel() # print(kernel.max()) if use_cuda: target_map = spherical_conv( th.from_numpy( target.reshape(1, 1, *target.shape) ).cuda(), th.from_numpy(kernel.reshape(1, 1, *kernel.shape)).cuda(), kernel_rad=self.kernel_rad, padding_mode=0 ).view(1, self.frame_h, self.frame_w) else: target_map = spherical_conv( th.from_numpy( target.reshape(1, 1, *target.shape) ), th.from_numpy(kernel.reshape(1, 1, *kernel.shape)), kernel_rad=self.kernel_rad, padding_mode=0 ).view(1, self.frame_h, self.frame_w) return target_map.data.float() / len(self.target[item])