Ejemplo n.º 1
0
    def test(self):
        """Run evaluation of the model
        Specify LOG_DIR to point to the saved checkpoint directory
        """

        if self.restore_check is None:
            raise RuntimeError(
                'restore did not succeed, pleas check if you set config.LOG_DIR correctly'
            )

        self.restore_check.assert_existing_objects_matched(
        ).assert_nontrivial_match()

        # Place tensors on the CPU
        with tf.device('/CPU:0'):
            dataset = Dataset()
            ds_test = dataset.get_test()

        start = time.time()
        print('Start of Testing')

        mpjpe, mpjpe_aligned, sequences = [], [], []

        total = int(self.config.NUM_TEST_SAMPLES / self.config.BATCH_SIZE)
        for image_data in tqdm(ds_test,
                               total=total,
                               position=0,
                               desc='testing'):
            image, kp3d, sequence = image_data[0], image_data[1], image_data[2]
            kp3d_mpjpe, kp3d_mpjpe_aligned = self._test_step(image, kp3d)

            mpjpe.append(kp3d_mpjpe)
            mpjpe_aligned.append(kp3d_mpjpe_aligned)
            sequences.append(sequence)

        print('Time taken for testing {} sec\n'.format(time.time() - start))

        def convert(tensor, num=None):
            if num is None:
                num = self.config.NUM_KP3D
            return tf.squeeze(tf.reshape(tf.stack(tensor), [-1, num]))

        mpjpe, mpjpe_aligned, sequences = convert(mpjpe), convert(
            mpjpe_aligned), convert(sequences, 1)
        result_dict = {
            "kp3d_mpjpe": mpjpe,
            "kp3d_mpjpe_aligned": mpjpe_aligned,
            "seq": sequences,
        }

        return result_dict
Ejemplo n.º 2
0
    def test(self, return_kps=False):
        """Run evaluation of the model
        Specify LOG_DIR to point to the saved checkpoint directory

        Args:
            return_kps: set to return keypoints - default = False
        """

        if self.restore_check is None:
            raise RuntimeError(
                'restore did not succeed, pleas check if you set config.LOG_DIR correctly'
            )

        if self.config.INITIALIZE_CUSTOM_REGRESSOR:
            self.restore_check.assert_nontrivial_match()
        else:
            self.restore_check.assert_existing_objects_matched(
            ).assert_nontrivial_match()

        # Place tensors on the CPU
        with tf.device('/CPU:0'):
            dataset = Dataset()
            ds_test = dataset.get_test()

        start = time.time()
        print('Start of Testing')

        mpjpe, mpjpe_aligned, sequences, kps3d_pred, kps3d_real = [], [], [], [], []

        total = int(self.config.NUM_TEST_SAMPLES / self.config.BATCH_SIZE)
        for image_data in tqdm(ds_test,
                               total=total,
                               position=0,
                               desc='testing'):
            image, kp3d, sequence = image_data[0], image_data[1], image_data[2]
            kp3d_mpjpe, kp3d_mpjpe_aligned, predict_kp3d, real_kp3d = self._test_step(
                image, kp3d, return_kps=return_kps)

            if return_kps:
                kps3d_pred.append(predict_kp3d)
                kps3d_real.append(real_kp3d)

            mpjpe.append(kp3d_mpjpe)
            mpjpe_aligned.append(kp3d_mpjpe_aligned)
            sequences.append(sequence)

        print('Time taken for testing {} sec\n'.format(time.time() - start))

        def convert(tensor, num=None, is_kp=False):
            if num is None:
                num = self.config.NUM_KP3D
            if is_kp:
                return tf.squeeze(tf.reshape(tf.stack(tensor), [-1, num, 3]))

            return tf.squeeze(tf.reshape(tf.stack(tensor), [-1, num]))

        mpjpe, mpjpe_aligned, sequences = convert(mpjpe), convert(
            mpjpe_aligned), convert(sequences, 1)
        result_dict = {
            "kp3d_mpjpe": mpjpe,
            "kp3d_mpjpe_aligned": mpjpe_aligned,
            "seq": sequences,
        }

        if return_kps:
            kps3d_pred, kps3d_real = convert(kps3d_pred,
                                             is_kp=True), convert(kps3d_real,
                                                                  is_kp=True)
            result_dict.update({
                'kps3d_pred': kps3d_pred,
                'kps3d_real': kps3d_real
            })

        return result_dict