Exemplo n.º 1
0
def test_get_unnamed_file_in_archive():
    with hold_file_root(get_artemis_data_path('file_getter_tests'),
                        delete_after=True,
                        delete_before=True):
        path = get_file_in_archive(
            url=
            'https://drive.google.com/uc?export=download&id=0B4IfiNtPKeSATWZXWjEyd1FsRG8',
            subpath='testzip/test_file.txt')
        with open(path) as f:
            txt = f.read()
        assert txt == 'blah blah blah'
Exemplo n.º 2
0
def load_ilsvrc_video(identifier,
                      size=None,
                      resize_mode='scale_crop',
                      cut_edges=True,
                      cut_edges_thresh=5):
    """
    Load a file from the ILSVRC Dataset.  The first time this is run, it will download an 8GB file, so be patient.

    Note: If you are using the same videos repeatedly, and applying resizing, you may want to call this function as:
        memoize_to_disk(load_ilsvrc_video)(identifier, size, ...)
    This will save you time on future runs.

    :param identifier: The file-name of the video, not including the extension.  Eg: 'ILSVRC2015_train_00249001'
    :param size:
    :param cut_edges:
    :param cut_edges_thresh:
    :return:
    """

    print('Downloading ILSVER2015... this may take a while...')
    archive_folder_path = get_archive(
        relative_path='data/ILSVRC2015',
        url=
        'http://vision.cs.unc.edu/ilsvrc2015/ILSVRC2015_VID_snippets_final.tar.gz'
    )
    print('Done.')
    subpath = \
        'ILSVRC2015/Data/VID/snippets/test' if 'test' in identifier else \
        'ILSVRC2015/Data/VID/snippets/val' if 'val' in identifier else \
        'ILSVRC2015/Data/VID/snippets/train/ILSVRC2015_VID_train_0001/' if os.path.exists(os.path.join(archive_folder_path, 'ILSVRC2015/Data/VID/snippets/train/ILSVRC2015_VID_train_0001/', identifier + '.mp4')) else \
        'ILSVRC2015/Data/VID/snippets/train/ILSVRC2015_VID_train_0002/' if os.path.exists(os.path.join(archive_folder_path, 'ILSVRC2015/Data/VID/snippets/train/ILSVRC2015_VID_train_0002/', identifier + '.mp4')) else \
        'ILSVRC2015/Data/VID/snippets/train/ILSVRC2015_VID_train_0003/' if os.path.exists(os.path.join(archive_folder_path, 'ILSVRC2015/Data/VID/snippets/train/ILSVRC2015_VID_train_0003/', identifier + '.mp4')) else \
        bad_value(identifier, 'Could not find identifier: {}'.format(identifier, ))

    print('Loading %s' % (identifier, ))
    full_path = get_file_in_archive(
        relative_path='data/ILSVRC2015',
        subpath=os.path.join(subpath, identifier + '.mp4'),
        url=
        'http://vision.cs.unc.edu/ilsvrc2015/ILSVRC2015_VID_snippets_final.tar.gz'
    )
    video = smart_load_video(full_path,
                             size=size,
                             cut_edges=cut_edges,
                             resize_mode=resize_mode,
                             cut_edges_thresh=cut_edges_thresh)
    print('Done.')
    return video
Exemplo n.º 3
0
def test_unpack_zip():

    with hold_file_root(get_artemis_data_path('file_getter_tests'), delete_after=True, delete_before=True):
        assert not os.path.exists(get_artemis_data_path('tests/test_tar_zip'))

        for _ in xrange(2):  # (Second time to check caching)

            local_file = get_file_in_archive(
                relative_path= 'tests/test_zip_zip',
                url = 'https://drive.google.com/uc?export=download&id=0B4IfiNtPKeSATWZXWjEyd1FsRG8',
                subpath = 'testzip/test_file.txt'
                )

            with open(local_file) as f:
                txt = f.read()

            assert txt == 'blah blah blah'
Exemplo n.º 4
0
def test_unpack_zip():

    with hold_file_root(get_artemis_data_path('file_getter_tests'),
                        delete_after=True,
                        delete_before=True):
        assert not os.path.exists(get_artemis_data_path('tests/test_tar_zip'))

        for _ in xrange(2):  # (Second time to check caching)

            local_file = get_file_in_archive(
                relative_path='tests/test_zip_zip',
                url=
                'https://drive.google.com/uc?export=download&id=0B4IfiNtPKeSATWZXWjEyd1FsRG8',
                subpath='testzip/test_file.txt')

            with open(local_file) as f:
                txt = f.read()

            assert txt == 'blah blah blah'
Exemplo n.º 5
0
def test_unpack_tar_gz():

    if os.path.exists(get_local_path('tests/test_tar_zip')):
        shutil.rmtree(get_local_path('tests/test_tar_zip'))
    if os.path.exists(get_local_path('tests/test_tar_zip.tar.gz')):
        os.remove(get_local_path('tests/test_tar_zip.tar.gz'))

    for _ in xrange(2):  # (Second time to check caching)

        local_file = get_file_in_archive(
            relative_path= 'tests/test_tar_zip',
            url = 'https://drive.google.com/uc?export=download&id=0B4IfiNtPKeSAbmp6VEVJdjdSSlE',
            subpath = 'testzip/test_file.txt'
            )

        with open(local_file) as f:
            txt = f.read()

        assert txt == 'blah blah blah'
Exemplo n.º 6
0
def test_unpack_zip():

    if os.path.exists(get_artemis_data_path('tests/test_zip_zip')):
        shutil.rmtree(get_artemis_data_path('tests/test_zip_zip'))
    if os.path.exists(get_artemis_data_path('tests/test_zip_zip.zip')):
        os.remove(get_artemis_data_path('tests/test_zip_zip.zip'))

    for _ in xrange(2):  # (Second time to check caching)

        local_file = get_file_in_archive(
            relative_path= 'tests/test_zip_zip',
            url = 'https://drive.google.com/uc?export=download&id=0B4IfiNtPKeSATWZXWjEyd1FsRG8',
            subpath = 'testzip/test_file.txt'
            )

        with open(local_file) as f:
            txt = f.read()

        assert txt == 'blah blah blah'
Exemplo n.º 7
0
def load_ilsvrc_video(identifier, size = None, resize_mode='scale_crop', cut_edges=True, cut_edges_thresh=5):
    """
    Load a file from the ILSVRC Dataset.  The first time this is run, it will download an 8GB file, so be patient.

    Note: If you are using the same videos repeatedly, and applying resizing, you may want to call this function as:
        memoize_to_disk(load_ilsvrc_video)(identifier, size, ...)
    This will save you time on future runs.

    :param identifier: The file-name of the video, not including the extension.  Eg: 'ILSVRC2015_train_00249001'
    :param size:
    :param cut_edges:
    :param cut_edges_thresh:
    :return:
    """

    print ('Downloading ILSVER2015... this may take a while...')
    archive_folder_path = get_archive(
        relative_path='data/ILSVRC2015',
        url='http://vision.cs.unc.edu/ilsvrc2015/ILSVRC2015_VID_snippets_final.tar.gz'
        )
    print ('Done.')
    subpath = \
        'ILSVRC2015/Data/VID/snippets/test' if 'test' in identifier else \
        'ILSVRC2015/Data/VID/snippets/val' if 'val' in identifier else \
        'ILSVRC2015/Data/VID/snippets/train/ILSVRC2015_VID_train_0001/' if os.path.exists(os.path.join(archive_folder_path, 'ILSVRC2015/Data/VID/snippets/train/ILSVRC2015_VID_train_0001/', identifier + '.mp4')) else \
        'ILSVRC2015/Data/VID/snippets/train/ILSVRC2015_VID_train_0002/' if os.path.exists(os.path.join(archive_folder_path, 'ILSVRC2015/Data/VID/snippets/train/ILSVRC2015_VID_train_0002/', identifier + '.mp4')) else \
        'ILSVRC2015/Data/VID/snippets/train/ILSVRC2015_VID_train_0003/' if os.path.exists(os.path.join(archive_folder_path, 'ILSVRC2015/Data/VID/snippets/train/ILSVRC2015_VID_train_0003/', identifier + '.mp4')) else \
        bad_value(identifier, 'Could not find identifier: {}'.format(identifier, ))

    print('Loading %s' % (identifier, ))
    full_path = get_file_in_archive(
        relative_path='data/ILSVRC2015',
        subpath=os.path.join(subpath, identifier+'.mp4'),
        url='http://vision.cs.unc.edu/ilsvrc2015/ILSVRC2015_VID_snippets_final.tar.gz'
        )
    video = smart_load_video(full_path, size=size, cut_edges=cut_edges, resize_mode=resize_mode, cut_edges_thresh=cut_edges_thresh)
    print('Done.')
    return video
Exemplo n.º 8
0
def test_get_unnamed_file_in_archive():
    with hold_file_root(get_artemis_data_path('file_getter_tests'), delete_after=True, delete_before=True):
        path = get_file_in_archive(url='https://drive.google.com/uc?export=download&id=0B4IfiNtPKeSATWZXWjEyd1FsRG8', subpath='testzip/test_file.txt')
        with open(path) as f:
                txt = f.read()
        assert txt == 'blah blah blah'