Pytorch에서 meshgrid 만들기
''' x : forward direction y : side (left) direction ''' s, b, c, h, w = seq_z.size() h_meters = self.cfg['bev']['h_meters'] w_meters = self.cfg['bev']['w_meters'] h_grid = torch.linspace(0, h_meters, h) - (h_meters / 2) w_grid = torch.linspace(0, w_meters, w) - (w_meters / 2) grid_x, grid_y = torch.meshgrid(torch.flip(h_grid, dims=(0,)), torch.flip(w_grid, dims=(0,)), indexing='ij') grid = torch..
더보기
Gaussian, LogGaussian PDF in Pytorch
def GaussianPDF(mean, logvar, z): r""" Return the PDF value of z in N(mean,exp(logvar)) mean, logvar : [*, dim_z] z : [*, N, dim_z] return: [*, N, dim_z] """ if type(mean) is torch.Tensor: mean, logvar = mean.unsqueeze(-2), logvar.unsqueeze(-2) return 1/(np.sqrt(2*np.pi)*torch.exp(logvar*0.5)) * torch.exp(-((z-mean)**2) / (2*torch.exp(logvar))) elif type(mean) is np.ndarray: mean, logvar = np.ex..
더보기
Implement KL Divergence using Pytorch
def GaussianPDF(mean, logvar, z): r""" Return the PDF value of z in N(mean,exp(logvar)) mean, logvar : [*, dim_z] z : [*, N, dim_z] return: [*, N, dim_z] """ if type(mean) is torch.Tensor: mean, logvar = mean.unsqueeze(-2), logvar.unsqueeze(-2) return 1/(np.sqrt(2*np.pi)*torch.exp(logvar*0.5)) * torch.exp(-((z-mean)**2) / (2*torch.exp(logvar))) elif type(mean) is np.ndarray: mean, logvar = np.ex..
더보기