def visualize_pc_with_svd(): num_points = 1024 model_idx = 5 gpu_idx = 0 original_points, _ = provider.load_single_model(model_idx=model_idx, test_train='train', file_idxs=0, num_points=num_points) original_points = provider.rotate_point_cloud_by_angle(original_points, np.pi/2) # #Simple plane sanity check # original_points = np.concatenate([np.random.rand(2, 1024), np.zeros([1, 1024])],axis=0) # R = np.array([[0.7071, 0, 0.7071], # [0, 1, 0], # [-0.7071, 0, 0.7071]]) # original_points = np.transpose(np.dot(R ,original_points)) original_points = np.expand_dims(original_points,0) pc_util.pyplot_draw_point_cloud(original_points[0,:,:]) sess = tf_util.get_session(gpu_idx, limit_gpu=True) points_pl = tf.placeholder(tf.float32, shape=(1, num_points, 3)) svd_op = tf_util.pc_svd(points_pl) rotated_points = sess.run(svd_op, feed_dict={points_pl:original_points}) pc_util.pyplot_draw_point_cloud(rotated_points[0,:,:]) plt.show()
def main(): BASE_DIR = os.path.dirname(os.path.abspath(__file__)) sys.path.append(BASE_DIR + '/visualization') log_dir = 'log_fisher_grid5_nonlinear' #Load gaussians # gmm_filename = os.path.join(log_dir,'gmm.p') # gmm = pickle.load(open(gmm_filename, "rb")) # parameters_filename = os.path.join(log_dir,'parameters.p') # PARAMETERS = pickle.load(open(parameters_filename, "rb")) #Create new gaussian subdev = 10 variance = 0.01 gmm = utils.get_grid_gmm(subdivisions=[subdev, subdev, subdev], variance=variance) class helper_struct(): def __init__(self): self.num_gaussians = subdev self.gmm_type = 'grid' PARAMETERS = helper_struct() gaussian_index = 740 num_points = 1024 model_idx = 0 n_gaussians = np.power( PARAMETERS.num_gaussians, 3) if PARAMETERS.gmm_type == 'grid' else PARAMETERS.num_gaussians points, _ = provider.load_single_model(model_idx=model_idx, test_train='train', file_idxs=0, num_points=num_points) g_pts, g_probs = utils.get_gaussian_points(points, gmm, idx=gaussian_index, thresh=0.01) #draw_gaussian_points(points, g_pts, gmm, idx=gaussian_index, ax=None, display=True, color_val=g_probs) #fv = utils.fisher_vector(points, gmm, normalization=True) # d_pi = fv[0:n_gaussians] # mean_d_pi = 0.02 # ax=draw_point_cloud(points) # draw_gaussians(gmm, ax=ax, display=True, mappables=d_pi, thresh=mean_d_pi) per_point_dpi, per_point_d_mu, per_point_d_sigma = utils.fisher_vector_per_point( points, gmm) visualize_derivatives(points, gmm, gaussian_index, per_point_dpi, per_point_d_mu, per_point_d_sigma)
e = (2 * beta[:, 2] / norm_N0).view(-1, 1, 1) f = (beta[:, 4] / norm_N0).view(-1, 1, 1) g = (2 * beta[:, 3] / norm_N0).view(-1, 1, 1) II = torch.cat( [torch.cat([e, f], dim=2), torch.cat([f, g], dim=2)], dim=1) M_weingarten = -torch.bmm(torch.inverse(I), II) curvatures, dirs = torch.symeig(M_weingarten, eigenvectors=True) #faster dirs = torch.cat( [dirs, torch.zeros(dirs.shape[0], 2, 1, device=dirs.device)], dim=2) # pad zero in the normal direction return curvatures, dirs if __name__ == "__main__": model_idx = 0 num_points = 1024 gmm = get_3d_grid_gmm(subdivisions=[5, 5, 5], variance=0.04) points = provider.load_single_model(model_idx=model_idx, train_file_idxs=0, num_points=num_points) points = np.tile(np.expand_dims(points, 0), [128, 1, 1]) fv_gpu = get_fisher_vectors(points, gmm, normalization=True)