Esempio n. 1
0
def num_trajlets(dataset: TrajDataset, length=4.8, overlap=2):
    trajs = dataset.get_trajectories(label="pedestrian")
    trajlets = split_trajectories(trajs,
                                  length,
                                  overlap,
                                  static_filter_thresh=0.)
    non_static_trajlets = split_trajectories(trajs,
                                             length,
                                             overlap,
                                             static_filter_thresh=1.)
    return len(trajlets), len(non_static_trajlets)
Esempio n. 2
0
def ttc(all_frames, name, trajlets):
    all_ttc = []
    Rp = 0.33  #assume pedestrians radius is 0.33
    new_frames = []
    for frame in all_frames:
        frame.reset_index(inplace=True)
        #if there is only one pedestrian at that time, or encounter invalid vel value
        if len(frame.index) < 2 or frame['vel_x'].isnull().values.any(
        ) or frame['vel_y'].isnull().values.any():
            continue

        #calculate ttc for each pair
        x_4d = np.stack((frame.pos_x.values, frame.pos_y.values,
                         frame.vel_x.values, frame.vel_y.values),
                        axis=1)
        DCA, TTCA = DCA_MTX(x_4d)

        for i in range(len(TTCA)):
            #find out ttc of one agent
            ttc = [
                TTCA[i][j] for j in range(len(TTCA[i]))
                if DCA[i][j] < 2 * Rp and TTCA[i][j] > 0
            ]
            #find out min ttc for one agent
            if len(ttc) > 0:
                min_ttc = np.min(ttc)
                frame.loc[i, 'ttc'] = min_ttc

            min_dca = np.min([j for j in DCA[i] if j > 0])
            frame.loc[i, 'dca'] = min_dca

        new_frames.append(frame)
    new_frames = pd.concat(new_frames)
    new_traj = TrajDataset()
    new_traj.data = new_frames
    trajs = new_traj.get_trajectories(label="pedestrian")
    trajlets[name] = split_trajectories(trajs, to_numpy=False)

    #average local density o each trajlet
    avg_traj_ttc = []
    avg_traj_dca = []
    for trajlet in trajlets[name]:
        avg_traj_ttc.append(np.min(trajlet['ttc'].dropna()))  #min of min
        avg_traj_dca.append(np.min(trajlet['dca'].dropna()))  #min of min

    return avg_traj_ttc, avg_traj_dca
Esempio n. 3
0
def local_density(all_frames,trajlets,name):
    #define local density function
    #for all pedestrians at that time, find its distance to NN
    distNN = []
    dens_t = []
    a=1
    new_frames = []
    for frame in all_frames:
       
        if len(frame)>1:
            #find pairwise min distance
            distNN.append([])
            dens_t.append([])
            dist = squareform(pdist(frame[['pos_x','pos_y']].values))
            pair_dist = []
            for pi in dist:
                
                pair_dist.append(np.array(pi))
                min_pi = [j for j in pi if j>0.01]
                if len(min_pi) == 0:
                    min_dist = 0.01
                else:
                    min_dist = np.min(min_pi)
                distNN[-1].append(min_dist)

            #calculate local density for agent pj
            for pj in range(len(dist)):
                dens_t_i = 1/(2*np.pi)*np.sum(1/((a*np.array(distNN[-1]))**2)*np.exp(-np.divide((pair_dist[pj]**2),(2*(a*np.array(distNN[-1]))**2))))
                dens_t[-1].append(dens_t_i)
                frame.loc[frame.index[pj],'p_local'] = dens_t_i
        new_frames.append(frame)
    new_frames = pd.concat(new_frames)
    new_traj = TrajDataset()
    new_traj.data = new_frames

     
    trajs = new_traj.get_trajectories(label="pedestrian")
    trajlets[name] = split_trajectories(trajs, to_numpy=False)

    #average local density for each trajlet
    avg_traj_plocal=[]
    for trajlet in trajlets[name]:
        avg_traj_plocal.append(np.max(trajlet['p_local']))

               
    return avg_traj_plocal
def get_trajlets(opentraj_root, dataset_names):
    trajlets = {}

    # Make a temp dir to store and load trajlets (no splitting anymore)
    trajlet_dir = os.path.join(opentraj_root, 'trajlets')
    if not os.path.exists(trajlet_dir): os.makedirs(trajlet_dir)
    for dataset_name in dataset_names:
        trajlet_npy_file = os.path.join(trajlet_dir, dataset_name + '-trl.npy')
        if os.path.exists(trajlet_npy_file):
            trajlets[dataset_name] = np.load(trajlet_npy_file)
            print("loading trajlets from: ", trajlet_npy_file)
        else:
            ds = get_datasets(opentraj_root, [dataset_name])[dataset_name]
            trajs = ds.get_trajectories(label="pedestrian")
            trajlets[dataset_name] = split_trajectories(trajs, to_numpy=True)
            np.save(trajlet_npy_file, trajlets[dataset_name])
            print("writing trajlets ndarray into: ", trajlet_npy_file)

    return trajlets
Esempio n. 5
0
    # p(Xp|Xn)  = p(Xp, Xn) / p(Xn) = p(X) / p(Xn)

    euclidean_distances(trajlets)

    cE = 0
    for traj_i in trajlets:
        xi = traj_i.whole
        xoi = traj_i.obsv
        xpi = traj_i.pred
        for traj_j in trajlets:
            xj = traj_j.whole
            xoj = traj_j.obsv
            xpj = traj_j.pred
            # K_xi_xj = np.exp(-norm(x1 - x2) ** 2 / 2)

    return cE


if __name__ == "__main__":
    from toolkit.loaders.loader_eth import load_eth
    from toolkit.core.trajlet import split_trajectories, to_numpy

    eth_dataset = load_eth(
        "/home/cyrus/workspace2/OpenTraj/datasets/ETH/seq_eth/obsmat.txt")
    eth_trajs = eth_dataset.get_trajectories("pedestrian")
    eth_trajlets = split_trajectories(eth_trajs)
    to_numpy(eth_trajlets)

    eth_trajlets = np.stack(eth_trajlets)
    conditional_entropy(eth_trajlets)
Esempio n. 6
0
def grouping(dataset: TrajDataset):
    trajs = dataset.get_trajectories("pedestrian")
    trajlets = split_trajectories(trajs)
    for trajlet in trajlets:
        pass
    return