def predict(self, prefix, target_length):
        """
        Predict a sequence using the given prefix.
        """
        assert target_length > 0

        with torch.no_grad():
            prefix = prefix.reshape(prefix.shape[1], -1, 4)
            prefix = qeuler_np(prefix, 'zyx')
            prefix = qfix(euler_to_quaternion(prefix, 'zyx'))
            inputs = torch.from_numpy(
                prefix.reshape(1, prefix.shape[0], -1).astype('float32'))

            if self.use_cuda:
                inputs = inputs.cuda()

            predicted, hidden = self.model(inputs)
            frames = [predicted]

            for i in range(1, target_length):
                predicted, hidden = self.model(predicted, hidden)
                frames.append(predicted)

            result = torch.cat(frames, dim=1)
            return result.view(result.shape[0], result.shape[1], -1,
                               4).cpu().numpy()
Ejemplo n.º 2
0
    def predict(self, prefix, target_length):
        """
        Predict a sequence using the given prefix.
        """
        assert target_length > 0

        with torch.no_grad():
            prefix = prefix.reshape(prefix.shape[1], -1, 4)
            prefix = qeuler_np(prefix, 'zyx')
            prefix = qfix(euler_to_quaternion(prefix, 'zyx'))
            inputs = torch.from_numpy(
                prefix.reshape(1, prefix.shape[0], -1).astype('float32'))

            if self.use_cuda:
                inputs = inputs.cuda()

            #print("HELLOLLLEOOELLLEOO", inputs.shape, target_length)
            predicted, terms = self.model(
                inputs, target_length,
                0)  #teacher forcing ratio = 0 for testing
            frames = [predicted]

            #result = torch.cat(frames, dim=1)
            result = torch.cat(predicted, dim=1)
            return result.view(result.shape[0], result.shape[1], -1,
                               4).cpu().numpy()
Ejemplo n.º 3
0
def evaluate(model, test_data):
    errors = []
    for d in test_data:
        source = np.concatenate((d[0], d[1][:1]), axis=0).reshape(-1, 32 * 4)
        target = d[2].reshape(-1, 32 * 4)
        if model is None:
            target_predicted = np.tile(source[-1],
                                       target.shape[0]).reshape(-1, 32 * 4)
        else:
            target_predicted = model.predict(
                np.expand_dims(source, 0),
                target_length=np.max(frame_targets) + 1).reshape(-1, 32 * 4)

        target = qeuler_np(target[:target_predicted.shape[0]].reshape(-1, 4),
                           'zyx').reshape(-1, 96)
        target_predicted = qeuler_np(target_predicted.reshape(-1, 4),
                                     'zyx').reshape(-1, 96)
        e = np.sqrt(
            np.sum((target_predicted[:, 3:] - target[:, 3:])**2, axis=1))
        errors.append(e)
    errors = np.mean(np.array(errors), axis=0)
    return errors
 def compute_euler_angles(self, order):
     for subject in self._data.values():
         for action in subject.values():
             action['rotations_euler'] = qeuler_np(action['rotations'],
                                                   order,
                                                   use_gpu=self._use_gpu)