Beispiel #1
0
    else:
        snapshot_folder = join(FLAGS.exp, 'snapshots')

    # GPU configuration
    config = tf.ConfigProto()
    config.gpu_options.allow_growth = True

    with tf.Session(config=config) as sess:

        sess.run(tf.global_variables_initializer())
        saver = tf.train.Saver()
        load_previous_checkpoint(snapshot_folder,
                                 saver,
                                 sess,
                                 is_training=False)
        tflearn.is_training(False, session=sess)

        if FLAGS.eval_set == 'valid':
            _pred_scaled = sess.run(reconstr_img_scaled,
                                    feed_dict={img_inp: batch_ip})
            if FLAGS.visualize:
                for i in xrange(BATCH_SIZE):
                    cv2.imshow('', batch_ip[0])
                    print 'Displaying Pr scaled icp 1k'
                    print _pred_scaled
                    show3d_balls.showpoints(_pred_scaled[i], ballradius=3)

        else:
            print 'Invalid dataset. Choose from [shapenet, pix3d]'
            sys.exit(1)
Beispiel #2
0
def calculate_metrics(models,
                      batches,
                      pcl_gt_scaled,
                      pred_scaled,
                      indices=None):

    if FLAGS.visualize:
        iters = range(batches)
    else:
        iters = tqdm(range(batches))

    epoch_chamfer = 0.
    epoch_forward = 0.
    epoch_backward = 0.
    epoch_emd = 0.

    ph_gt = tf.placeholder(tf.float32, (BATCH_SIZE, NUM_EVAL_POINTS, 3),
                           name='ph_gt')
    ph_pr = tf.placeholder(tf.float32, (BATCH_SIZE, NUM_EVAL_POINTS, 3),
                           name='ph_pr')

    dists_forward, dists_backward, chamfer_distance = get_chamfer_metrics(
        ph_gt, ph_pr)
    emd = get_emd_metrics(ph_gt, ph_pr, BATCH_SIZE, NUM_EVAL_POINTS)

    for cnt in iters:
        start = time.time()

        if FLAGS.dataset == 'shapenet':
            batch_ip, batch_gt = fetch_batch_shapenet(models, indices, cnt,
                                                      BATCH_SIZE)
        elif FLAGS.dataset == 'pix3d':
            batch_ip, batch_gt = fetch_batch_pix3d(models, cnt, BATCH_SIZE)

        _gt_scaled, _pr_scaled = sess.run([pcl_gt_scaled, pred_scaled],
                                          feed_dict={
                                              pcl_gt: batch_gt,
                                              img_inp: batch_ip
                                          })

        _pr_scaled_icp = []

        for i in xrange(BATCH_SIZE):
            rand_indices = np.random.permutation(NUM_POINTS)[:NUM_EVAL_POINTS]
            T, _, _ = icp(_gt_scaled[i],
                          _pr_scaled[i][rand_indices],
                          tolerance=1e-10,
                          max_iterations=1000)
            _pr_scaled_icp.append(
                np.matmul(_pr_scaled[i][rand_indices], T[:3, :3]) - T[:3, 3])

        _pr_scaled_icp = np.array(_pr_scaled_icp).astype('float32')

        C, F, B, E = sess.run(
            [chamfer_distance, dists_forward, dists_backward, emd],
            feed_dict={
                ph_gt: _gt_scaled,
                ph_pr: _pr_scaled_icp
            })

        epoch_chamfer += C.mean() / batches
        epoch_forward += F.mean() / batches
        epoch_backward += B.mean() / batches
        epoch_emd += E.mean() / batches

        if FLAGS.visualize:
            for i in xrange(BATCH_SIZE):
                print '-' * 50
                print C[i], F[i], B[i], E[i]
                print '-' * 50
                cv2.imshow('', batch_ip[i])

                print 'Displaying Gt scaled 1k'
                show3d_balls.showpoints(_gt_scaled[i], ballradius=3)
                print 'Displaying Pr scaled icp 1k'
                show3d_balls.showpoints(_pr_scaled_icp[i], ballradius=3)

        if cnt % 10 == 0:
            print '%d / %d' % (cnt, batches)

    if not FLAGS.visualize:
        log_values(csv_path, epoch_chamfer, epoch_forward, epoch_backward,
                   epoch_emd)

    return
Beispiel #3
0
		)

		epoch_chamfer += C.mean() / batches
		epoch_forward += F.mean() / batches
		epoch_backward += B.mean() / batches
		epoch_emd += E.mean() / batches

		if FLAGS.visualize:
			for i in xrange(BATCH_SIZE):
				print '-'*50
				print C[i], F[i], B[i], E[i]
				print '-'*50
				cv2.imshow('', batch_ip[i])

				print 'Displaying Gt scaled 1k'
				show3d_balls.showpoints(_gt_scaled[i], ballradius=3)
				print 'Displaying Pr scaled icp 1k'
				show3d_balls.showpoints(_pr_scaled_icp[i], ballradius=3)
		
		if cnt%10 == 0:
			print '%d / %d' % (cnt, batches)

	if not FLAGS.visualize:
		log_values(csv_path, epoch_chamfer, epoch_forward, epoch_backward, epoch_emd)

	return

if __name__ == '__main__':

	# Create Placeholders
	img_inp = tf.placeholder(tf.float32, shape=(BATCH_SIZE, HEIGHT, WIDTH, 3), name='img_inp')