def handle_seq(self, x_seq, lookup_seq, PedsList_seq, angle):
        # add noise and rotate a trajectory
        vectorized_x_seq, first_values_dict = vectorize_seq(
            x_seq, PedsList_seq, lookup_seq)
        modified_x_seq = vectorized_x_seq.clone()
        mean = torch.FloatTensor([self.noise_mean, self.noise_mean])
        stddev = torch.FloatTensor([self.noise_std, self.noise_std])
        origin = (0, 0)

        for ind, frame in enumerate(vectorized_x_seq):
            for ped in PedsList_seq[ind]:
                selected_point = frame[lookup_seq[ped], :]
                # rotate a frame point
                rotated_point = rotate(origin, selected_point,
                                       math.radians(angle))
                noise = torch.normal(mean, stddev).clone()
                # add random noise
                modified_x_seq[ind, lookup_seq[ped],
                               0] = rotated_point[0] + noise[0]
                modified_x_seq[ind, lookup_seq[ped],
                               1] = rotated_point[1] + noise[1]
                # modified_x_seq[ind, lookup_seq[ped], :] = torch.cat(rotate(origin, first_values_dict[ped], math.radians(angle))) + modified_x_seq[ind, lookup_seq[ped], :]
                # roatate first frame value as well and add it back to get absoute coordinates
                modified_x_seq[ind, lookup_seq[ped], 0] = (rotate(
                    origin, first_values_dict[ped], math.radians(
                        angle)))[0] + modified_x_seq[ind, lookup_seq[ped], 0]
                modified_x_seq[ind, lookup_seq[ped], 1] = (rotate(
                    origin, first_values_dict[ped], math.radians(
                        angle)))[1] + modified_x_seq[ind, lookup_seq[ped], 1]

        return modified_x_seq
Exemple #2
0
def vectorize_traj(traj, nodesPresent, look_up):
    #wrap up for vectorizing traj
    traj, _ = vectorize_seq(Variable(torch.FloatTensor(traj)), nodesPresent, look_up)
    traj = np.array([seq.data.numpy() for seq in traj])
    return traj