Exemple #1
0
    def test_isjpeg(self):
        assert isjpeg('dummy.jpg')
        assert isjpeg('dummy.JPG')
        assert isjpeg('dummy.JpG')
        assert isjpeg('dummy.jpeg')
        assert isjpeg('dummy.JPEG')
        assert isjpeg('dummy.JPeG')

        assert not isjpeg('dummy.jpa')
        assert not isjpeg('dummy.jpA')
        assert not isjpeg('jpg')
Exemple #2
0
def get_minicub_data(data_path, train_split=0.5, **kwargs):
    classes = [x for x in listdir(data_path) if isdir(join(data_path, x))]

    classes.sort()
    num_training = int(len(classes) * train_split)

    image_paths = []

    for c in classes:
        images = [
            join(data_path, str(c), x)
            for x in listdir(join(data_path, str(c))) if isjpeg(x)
        ]
        image_paths.append(images)

    train_image_files = image_paths[:num_training]
    test_image_files = image_paths[num_training:]

    return train_image_files, test_image_files, None
Exemple #3
0
def get_imagenet_data(data_path, train_split=0.5, **kwargs):
    categories = [
        join(data_path, x) for x in listdir(data_path)
        if isdir(join(data_path, x))
    ]
    all_data = {}
    for category in categories:
        img_files = [x for x in listdir(category) if isjpeg(x)]
        for img in img_files:
            classname, imgid = tuple(img.split('_'))
            if classname not in all_data:
                all_data[classname] = []
            all_data[classname].append(join(category, img))
    all_data = list(all_data.values())
    num_training = int(ceil(len(all_data) * train_split))
    train_image_files = all_data[:num_training]
    test_image_files = all_data[num_training:]
    print('IMAGENET: train %d | test: %d' % (sum(
        len(i)
        for i in train_image_files), sum(len(j) for j in test_image_files)))
    return train_image_files, test_image_files, None
Exemple #4
0
def get_cars196_data(data_path, train_split=0.5, **kwargs):
    boxes = None  # CARS196 has no bbox information
    classes = [
        int(x) for x in listdir(data_path)
        if isdir(join(data_path, x)) and x.isdigit()
    ]

    classes.sort()
    num_training = int(len(classes) * train_split)

    image_paths = []
    for c in classes:
        images = [
            join(data_path, str(c), x)
            for x in listdir(join(data_path, str(c))) if isjpeg(x)
        ]
        image_paths.append(images)

    train_image_files = image_paths[:num_training]
    test_image_files = image_paths[num_training:]

    return train_image_files, test_image_files, boxes