예제 #1
0
def generate_3d_example():
    n_gaussians = 1
    variance = np.square(1.0 / n_gaussians)
    gmm = utils.get_grid_gmm(
        subdivisions=[n_gaussians, n_gaussians, n_gaussians],
        variance=variance)
    # points = np.array([[[0, 0, 0]]])
    points = get_3d_spiral()

    fig_images = []
    for i, point in enumerate(points):
        if point.ndim == 1:
            point = np.expand_dims(point, axis=0)
        pc_3dmfv = utils.get_3DmFV(point,
                                   gmm.weights_,
                                   gmm.means_,
                                   gmm.covariances_,
                                   normalize=True)
        fig_image = visualization.visualzie_3dmfv_gaussian_and_points(
            gmm,
            point,
            pc_3dmfv[0, :, :],
            display=False,
            export=False,
            export_path=OUTPUT_PATH + '/fv_3d' + str(i) + '.png')
        fig_images.append(fig_image)
    imageio.mimsave(OUTPUT_PATH + '/3d_fv.gif', fig_images)
예제 #2
0
def generate_3d_example_2():
    n_gaussians = 2
    variance = np.square(1.0/n_gaussians)
    gmm = utils.get_grid_gmm(subdivisions=[n_gaussians, n_gaussians, n_gaussians], variance=variance)
    points = utils.load_point_cloud_from_txt('car_130.txt')
    points = np.expand_dims(points, axis=0)
    pc_3dmfv = utils.get_3DmFV(points, gmm.weights_, gmm.means_, gmm.covariances_, normalize=True)
    fig_image = visualization.visualize_3dmfv_gaussian_and_points(gmm, np.squeeze(points), pc_3dmfv[0, :, :], display=False,
                                                                  export=True,
                                                                  export_path=OUTPUT_PATH + '/fv_3d_model' + '.png')
예제 #3
0
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)
예제 #4
0
def visualize_fv_pc_clas():
    num_points = 1024
    n_classes = 40
    clas = 'person'
    #Create new gaussian
    subdev = 5
    variance = 0.04
    export = False
    display = True
    exp_path = '/home/itzikbs/PycharmProjects/fisherpointnet/paper_images/'

    shape_names = provider.getDataFiles( \
        os.path.join(BASE_DIR, 'data/modelnet' + str(n_classes) + '_ply_hdf5_2048/shape_names.txt'))
    shape_dict = {shape_names[i]: i for i in range(len(shape_names))}

    gmm = utils.get_grid_gmm(subdivisions=[subdev, subdev, subdev], variance=variance)
    # compute fv
    w = tf.constant(gmm.weights_, dtype=tf.float32)
    mu = tf.constant(gmm.means_, dtype=tf.float32)
    sigma = tf.constant(gmm.covariances_, dtype=tf.float32)

    for clas in shape_dict:
        points = provider.load_single_model_class(clas=clas, ind=0, test_train='train', file_idxs=0, num_points=1024,
                                                  n_classes=n_classes)
        points = np.expand_dims(points,0)

        points_tensor = tf.constant(points, dtype=tf.float32)  # convert points into a tensor
        fv_tensor = tf_util.get_fv_minmax(points_tensor, w, mu, sigma, flatten=False)

        sess = tf_util.get_session(2)
        with sess:
            fv = fv_tensor.eval()
        #
        # visualize_single_fv_with_pc(fv_train, points, label_title=clas,
        #                      fig_title='fv_pc', type='paper', pos=[750, 800, 0, 0], export=export,
        #                      filename=BASE_DIR + '/paper_images/fv_pc_' + clas)

        visualize_fv(fv, gmm, label_title=[clas], max_n_images=5, normalization=True, export=export, display=display,
                     filename=exp_path + clas+'_fv', n_scales=1, type='none', fig_title='Figure')
        visualize_pc(points, label_title=clas, fig_title='figure', export=export, filename=exp_path +clas+'_pc')
        plt.close('all')