Esempio n. 1
0
def biwi(line):
    line = [e for e in line.split(' ') if e != '']
    return TrackRow(
        int(float(line[0]) - 1),  # shift from 1-index to 0-index
        int(float(line[1])),
        float(line[2]),
        float(line[4]))
Esempio n. 2
0
def get_trackrows(line):
    line = json.loads(line)
    track = line.get('track')
    if track is not None:
        return TrackRow(track['f'], track['p'], track['x'], track['y'],
                        track.get('prediction_number'))
    return None
Esempio n. 3
0
def crowds_interpolate_person(ped_id, person_xyf):
    ## Earlier
    # xs = np.array([x for x, _, _ in person_xyf]) / 720 * 12 # 0.0167
    # ys = np.array([y for _, y, _ in person_xyf]) / 576 * 12 # 0.0208

    ## Pixel-to-meter scale conversion according to
    ## https://github.com/agrimgupta92/sgan/issues/5
    xs = np.array([x for x, _, _ in person_xyf]) * 0.0210
    ys = np.array([y for _, y, _ in person_xyf]) * 0.0239

    fs = np.array([f for _, _, f in person_xyf])

    kind = 'linear'
    if len(fs) > 5:
        kind = 'cubic'

    x_fn = scipy.interpolate.interp1d(fs, xs, kind=kind)
    y_fn = scipy.interpolate.interp1d(fs, ys, kind=kind)

    frames = np.arange(min(fs) // 10 * 10 + 10, max(fs), 10)
    return [
        TrackRow(int(f), ped_id, x, y)
        for x, y, f in np.stack([x_fn(frames),
                                 y_fn(frames), frames]).T
    ]
Esempio n. 4
0
def edinburgh(filename_content_index):
    """Edinburgh Informatics Forum data reader.

    Original frame rate is 9fps.
    Every pixel corresponds to 24.7mm.
    http://homepages.inf.ed.ac.uk/rbf/FORUMTRACKING/
    """
    (_, whole_file), index = filename_content_index

    for line in whole_file.splitlines():
        line = line.strip()
        if not line.startswith('TRACK.R'):
            continue

        # get to track id
        line = line[7:]
        track_id, _, coordinates = line.partition('=')
        track_id = int(track_id) + index * 1000000

        # parse track
        for coordinates in coordinates.split(';'):
            if not coordinates:
                continue
            x, y, frame = coordinates.strip('[] ').split(' ')
            frame = int(frame) + index * 1000000
            if frame % 3 != 0:  # downsample frame rate
                continue
            yield TrackRow(frame, track_id,
                           float(x) * 0.0247,
                           float(y) * 0.0247)
Esempio n. 5
0
def mot(line):
    """Line reader for MOT files.

    MOT format:
    <frame>, <id>, <bb_left>, <bb_top>, <bb_width>, <bb_height>, <conf>, <x>, <y>, <z>
    """
    line = [e for e in line.split(',') if e != '']
    return TrackRow(int(float(line[0])), int(float(line[1])), float(line[7]),
                    float(line[8]))
Esempio n. 6
0
def wildtrack(filename_content):
    filename, content = filename_content

    frame = int(os.path.basename(filename).replace('.json', ''))
    for entry in json.loads(content):
        ped_id = entry['personID']
        position_id = entry['positionID']

        x = -3.0 + 0.025 * (position_id % 480)
        y = -9.0 + 0.025 * (position_id / 480)

        yield TrackRow(frame, ped_id, x, y)
Esempio n. 7
0
def syi(filename_content):
    """Tracking dataset in Grand Central.

    Yi_Pedestrian_Travel_Time_ICCV_2015_paper.pdf states that original
    frame rate is 25fps.

    Input rows are sampled every 20 frames. Assuming 25fps at recording,
    need to interpolate an additional row to get to 2.5 rows per second.
    """
    filename, whole_file = filename_content
    track_id = int(os.path.basename(filename).replace('.txt', ''))

    chunk = []
    last_row = None
    for line in whole_file.split('\n'):
        if not line:
            continue
        chunk.append(int(line))
        if len(chunk) < 3:
            continue

        # rough approximation of mapping to world coordinates (main concourse is 37m x 84m)
        new_row = TrackRow(chunk[2], track_id, chunk[0] * 30.0 / 1920,
                           chunk[1] * 70.0 / 1080)

        # interpolate one row to increase frame rate
        if last_row is not None:
            interpolated_row = TrackRow(
                int((last_row.frame + new_row.frame) / 2),
                track_id,
                (last_row.x + new_row.x) / 2,
                (last_row.y + new_row.y) / 2,
            )
            yield interpolated_row

        yield new_row
        chunk = []
        last_row = new_row
Esempio n. 8
0
def mot_xml(file_name):
    """PETS2009 dataset.

    Original frame rate is 7 frames / sec.
    """
    tree = xml.etree.ElementTree.parse(file_name)
    root = tree.getroot()
    for frame in root:
        f = int(frame.attrib['number'])
        if f % 2 != 0:  # reduce to 3.5 rows / sec
            continue

        for ped in frame.find('objectlist'):
            p = ped.attrib['id']
            box = ped.find('box')
            x = box.attrib['xc']
            y = box.attrib['yc']

            yield TrackRow(f, int(p), float(x) / 100.0, float(y) / 100.0)
Esempio n. 9
0
def dukemtmc(input_array, query_camera=5):
    """DukeMTMC dataset.

    Recorded at 59.940059 fps.

    Line format:
    [camera, ID, frame, left, top, width, height, worldX, worldY, feetX, feetyY]
    """
    for line in input_array:
        camera, person, frame, _, _, _, _, world_x, world_y, _, _ = line

        camera = int(camera)
        if camera != query_camera:
            continue

        frame = int(frame)
        if frame % 24 != 0:
            continue

        yield TrackRow(frame, int(person), world_x, world_y)
Esempio n. 10
0
def cff(line):
    line = [e for e in line.split(';') if e != '']

    ## Time Stamp
    time = [t for t in line[0].split(':') if t != '']

    ## Check Line Entry Valid
    if len(line) != 5:
        return None

    ## Check Time Entry Valid
    if len(time) != 4:
        return None

    ## Check Location
    if line[1] != 'PIW':
        return None

    ## Check Time Format
    if time[0][-3:] == 'T07':
        ped_id = int(line[4])
        f = 0
    elif time[0][-3:] == 'T17':
        ped_id = 100000 + int(line[4])
        f = 100000
    else:
        # "Time Format Incorrect"
        return None

    ## Extract Frame
    f += int(time[-3]) * 1000 + int(time[-2]) * 10 + int(time[-1][0])

    if f % 4 == 0:
        return TrackRow(
            f,  # shift from 1-index to 0-index
            ped_id,
            float(line[2]) / 1000,
            float(line[3]) / 1000)
    return None
Esempio n. 11
0
def car_data(filename_content):
    frame_id = int(filename_content[0].split('.')[0].split('/')[-1])
    ratio = 5.0 / 162  ## 162 pix = 5 m
    lines = filename_content[1].split('\n')
    ## First Line: ID, Front1x, Front1y, Front2x, Front2y, Back1x, Back1y, Back2x, Back2y, Type, Occlusion
    assert lines[
        0] == 'ID,Front1x,Front1y,Front2x,Front2y,Back1x,Back1y,Back2x,Back2y,Type,Occlusion'
    ## Last Line: ""
    assert lines[-1] == ''

    for line in lines[1:-1]:
        id_, F1x, F1y, F2x, F2y, B1x, B1y, B2x, B2y, type_, occ = line.split(
            ',')

        if int(type_) != 2:
            continue

        if int(frame_id) % 12 != 0:
            continue

        yield TrackRow(frame_id, int(id_), ratio * float(F1x),
                       ratio * float(F1y))
Esempio n. 12
0
def standard(line):
    line = [e for e in line.split('\t') if e != '']
    return TrackRow(int(float(line[0])), int(float(line[1])), float(line[2]),
                    float(line[3]))
Esempio n. 13
0
def controlled(line):
    line = [e for e in line.split(', ') if e != '']
    return TrackRow(int(float(line[0])), int(float(line[1])), float(line[2]),
                    float(line[3]))
Esempio n. 14
0
def trajnet_original(line):
    line = [e for e in line.split(' ') if e != '']
    return TrackRow(int(float(line[0])), int(float(line[1])), float(line[2]),
                    float(line[3]))
Esempio n. 15
0
def evaluation_trajnetplusplus_minadefde(model,
                                         test_data,
                                         test_primary_path,
                                         config,
                                         table=None):
    l2dis = []
    num_batches_per_epoch = test_data.cardinality().numpy()
    # Here we reconstruct the trajectories
    scenes_gt_batch = []
    scenes_sub_batch = []
    scenes_id_gt_batch = []
    for batch in tqdm(test_data, ascii=True):
        # Primary_path
        test_primary_path_local = [
            test_primary_path[row.numpy()] for row in batch["index"]
        ]
        scenes_id_gt, scenes_gt_all, scenes_by_id = zip(
            *test_primary_path_local)

        ## indexes is dictionary deciding which scenes are in which type
        indexes = {}
        for i in range(1, 5):
            indexes[i] = []
        ## sub-indexes
        sub_indexes = {}
        for i in range(1, 5):
            sub_indexes[i] = []
        for scene in scenes_by_id:
            tags = scene.tag
            main_tag = tags[0:1]
            sub_tags = tags[1]
            for ii in range(1, 5):
                if ii in main_tag:
                    indexes[ii].append(scene.scene)
                if ii in sub_tags:
                    sub_indexes[ii].append(scene.scene)
        # Here we perform the prediction
        if hasattr(config, 'add_social') and config.add_social:
            pred_out = model.predict([
                batch['obs_traj_' + config.coords_mode],
                batch['obs_optical_flow']
            ], batch['pred_traj_' + config.coords_mode].shape[1])
        else:
            pred_out = model.predict([batch['obs_traj_' + config.coords_mode]],
                                     batch['pred_traj_' +
                                           config.coords_mode].shape[1])
        # For all the trajectories in the batch
        for i, (obs_traj_gt, pred_traj_gt) in enumerate(
                zip(batch["obs_traj"], batch["pred_traj"])):
            normin = 1000.0
            diffmin = None
            for k in range(pred_out[i].shape[0]):
                # Conserve the x,y coordinates of the kth trajectory
                this_pred_out = pred_out[i, k, :, :2]  #[pred,2]
                # Convert it to absolute (starting from the last observed position)
                this_pred_out_abs = reconstruct(obs_traj_gt[-1], 0.0,
                                                this_pred_out, "rel")
                # Check shape is OK
                assert this_pred_out_abs.shape == this_pred_out.shape, (
                    this_pred_out_abs.shape, this_pred_out.shape)
                # Ground truth
                scenes_gt = scenes_gt_all[i][config.obs_len + 1:]
                print(
                    np.mean(
                        np.sqrt(
                            np.sum(np.square(pred_traj_gt - this_pred_out_abs),
                                   axis=1))))
            #print(scenes_gt)
            #print(pred_traj_gt)
            scenes_sub = [
                TrackRow(path.frame, path.pedestrian, x, y, 0, scenes_id_gt[i])
                for path, (x, y) in zip(scenes_gt, this_pred_out_abs)
            ]
            # Guardamos  en la lista del batch
            scenes_gt_batch.append([scenes_gt])
            scenes_sub_batch.append([scenes_sub])
            scenes_id_gt_batch.append(scenes_id_gt[i])

    # Evaluate
    logging.info("Calling TrajnetEvaluator with {} trajectories".format(
        len(scenes_sub_batch)))
    evaluator = TrajnetEvaluator([], scenes_gt_batch, scenes_id_gt_batch,
                                 scenes_sub_batch, indexes, sub_indexes,
                                 config)
    evaluator.aggregate('kf', True)
    results = {
        "Evaluation": evaluator.result(),
    }

    if table != None:
        logging.info("Creating results table")
        # Creamos la tabla de resultados
        table.add_collision_entry("Our_Model", "NA")
        final_result, sub_final_result = table.add_entry('Our_Model', results)
    return table