def main():
    args = parse_args()
    if args.dataset == 'breakfast':
        train_segments, _, _ = breakfast.get_data(split='train')
    else:
        raise ValueError('no such dataset')

    video_names = []
    for segment in train_segments:
        video_name = segment['video-name']
        video_names.append(video_name)

    video_names = np.unique(video_names).reshape(-1)
    video_dirs = [os.path.join(breakfast.EXTRACTED_IMAGES_DIR, video) for video in video_names]
    mean, std = compute_mean_std(video_dirs=video_dirs)
    np.save(breakfast.MEAN_FILE, mean)
    np.save(breakfast.STD_FILE, std)
Esempio n. 2
0
def _parse_split_data(split, feat_len):
    segments, labels, logits = breakfast.get_data(split)
    valid_segments = []
    valid_labels = []
    valid_logits = []
    for i, segment in enumerate(tqdm(segments)):
        start, end = segment['start'], segment['end']
        i3d_feats = breakfast.read_i3d_data(segment['video-name'],
                                            window=[start, end],
                                            i3d_length=feat_len)
        if len(i3d_feats
               ) > 0 and 48 > logits[i] > 0:  # remove walk in and walk out.
            segment['end'] = segment['start'] + len(i3d_feats)
            valid_segments.append(segment)
            valid_labels.append(labels[i])
            valid_logits.append(logits[i])
    return [valid_segments, valid_labels, valid_logits]
Esempio n. 3
0
def _parse_split_data(split):
    segments, labels, logits = breakfast.get_data(split)
    valid_segments = []
    valid_labels = []
    valid_logits = []
    for i, segment in enumerate(tqdm(segments)):
        start, end = segment['start'], segment['end']
        video_name = segment['video-name']
        video_dir = os.path.join(breakfast.EXTRACTED_IMAGES_DIR, video_name)
        n_video_frames = len(os.listdir(video_dir))
        end = min(n_video_frames, end)
        n_frames = end - start
        if n_frames > 0 and 48 > logits[i] > 0:  # remove walk in and walk out.
            segment['end'] = end
            valid_segments.append(segment)
            valid_labels.append(labels[i])
            valid_logits.append(logits[i])
    return [valid_segments, valid_labels, valid_logits]

def _display_distribution(labels, n_labels):
    for label in labels:
        assert label < n_labels, 'some labels are not smaller than {}'.format(
            n_labels)

    fig = plt.hist(x=labels, bins=n_labels)
    plt.title('Test Label Distribution')
    plt.xlabel("Labels")
    plt.ylabel("Frequency")
    plt.show()


if __name__ == '__main__':
    _, labels, logits = breakfast.get_data(split='test')

    logits = [logit for logit in logits if logit]
    logits = [logit for logit in logits if logit < 48]
    # todo: uncomment to view sorted version
    # logit_counter = Counter(logits)
    # most_common = logit_counter.most_common()
    # remap = {}
    # for i in range(len(most_common)):
    #     mc_tuple = most_common[i]
    #     remap[mc_tuple[0]] = i
    # logits = [remap[logit] for logit in logits]

    logits = np.array(logits).reshape(-1)
    _display_distribution(logits, n_labels=max(logits) + 1)