Ejemplo n.º 1
0
            # need [img, label, pose(camera meta data), dataID]
            img_all_view, labels, poses, data_id, mesh = data.fetch()
            feed_dict.update({placeholders['features']: mesh})
            feed_dict.update({placeholders['img_inp']: img_all_view})
            feed_dict.update({placeholders['labels']: labels})
            feed_dict.update({placeholders['cameras']: poses})
            # ---------------------------------------------------------------
            _, dists, summaries, out1l, out2l = sess.run([model.opt_op, model.loss, model.merged_summary_op, model.output1l, model.output2l], feed_dict=feed_dict)
            # ---------------------------------------------------------------
            all_loss[iters] = dists
            mean_loss = np.mean(all_loss[np.where(all_loss)])
            print('Epoch {}, Iteration {}, Mean loss = {}, iter loss = {}, {}, data id {}'.format(current_epoch, iters + 1, mean_loss, dists, data.queue.qsize(), data_id))
            train_writer.add_summary(summaries, step)
            if (iters + 1) % 1000 == 0:
                plot_scatter(pt=out2l, data_name=data_id, plt_path=epoch_plt_dir)
        # ---------------------------------------------------------------
        # Save model
        model.save(sess=sess, ckpt_path=model_dir, step=current_epoch)
        train_loss.write('Epoch {}, loss {}\n'.format(current_epoch, mean_loss))
        train_loss.flush()
    # ---------------------------------------------------------------
    data.shutdown()
    print('CNN-GCN Optimization Finished!')


if __name__ == '__main__':
    print('=> set config')
    args = execute()
    pprint.pprint(vars(args))
    main(args)
Ejemplo n.º 2
0
def main():
    args = execute()
    os.environ['CUDA_VISIBLE_DEVICES'] = str(args.gpu_id)
    pred_file_list = os.path.join(args.test_results_path,
                                  args.p2mpp_experiment_name, '*.xyz')
    xyz_list_path = glob.glob(pred_file_list)

    xyz1 = tf.placeholder(tf.float32, shape=(None, 3))
    xyz2 = tf.placeholder(tf.float32, shape=(None, 3))
    dist1, idx1, dist2, idx2 = nn_distance(xyz1, xyz2)
    config = tf.ConfigProto()
    config.gpu_options.allow_growth = True
    config.allow_soft_placement = True
    sess = tf.Session(config=config)

    #A f1-score will be calculated for each threshold.
    threshold = [0.00005, 0.00010, 0.00015, 0.00020]
    name = {
        '02828884': 'bench',
        '03001627': 'chair',
        '03636649': 'lamp',
        '03691459': 'speaker',
        '04090263': 'firearm',
        '04379243': 'table',
        '04530566': 'watercraft',
        '02691156': 'plane',
        '02933112': 'cabinet',
        '02958343': 'car',
        '03211117': 'monitor',
        '04256520': 'couch',
        '04401088': 'cellphone'
    }
    length = {
        '02828884': 0,
        '03001627': 0,
        '03636649': 0,
        '03691459': 0,
        '04090263': 0,
        '04379243': 0,
        '04530566': 0,
        '02691156': 0,
        '02933112': 0,
        '02958343': 0,
        '03211117': 0,
        '04256520': 0,
        '04401088': 0
    }
    sum_pred = {
        '02828884': np.zeros(4),
        '03001627': np.zeros(4),
        '03636649': np.zeros(4),
        '03691459': np.zeros(4),
        '04090263': np.zeros(4),
        '04379243': np.zeros(4),
        '04530566': np.zeros(4),
        '02691156': np.zeros(4),
        '02933112': np.zeros(4),
        '02958343': np.zeros(4),
        '03211117': np.zeros(4),
        '04256520': np.zeros(4),
        '04401088': np.zeros(4)
    }

    index = 0
    for pred_path in xyz_list_path:
        filename = os.path.basename(pred_path)
        #Ground_thruth contains an image of the reconstructed object in [0] and the point cloud and normals on [1]
        ground_truth_path = os.path.join(args.test_models_path,
                                         filename.replace(".xyz", ".dat"))
        ground = pickle.load(open(ground_truth_path, 'rb'),
                             encoding='bytes')[1][:, :3]
        predict = np.loadtxt(pred_path)

        class_id = pred_path.split('/')[-1].split('_')[0]
        length[class_id] += 1.0
        d1, i1, d2, i2 = sess.run([dist1, idx1, dist2, idx2],
                                  feed_dict={
                                      xyz1: predict,
                                      xyz2: ground
                                  })
        sum_pred[class_id] += f_score(predict, ground, d1, i1, d2, i2,
                                      threshold)

        index += 1

    log_dir = os.path.join(args.misc_results_path, args.p2mpp_experiment_name)
    if not os.path.exists(log_dir):
        os.makedirs(log_dir)

    log_path = os.path.join(log_dir, 'f1_score.log')

    with open(log_path, 'a+') as log:
        for item in length:
            number = length[item] + 1e-6
            score = sum_pred[item] / number
            log.write(", ".join(
                [item, name[item],
                 str(length[item]),
                 str(score), "\n"]))

    sess.close()