Beispiel #1
0
def test_imgqueue_repr():
    file_queue = dl.FileQueue()
    file_queue.load_epochs(files)
    sleep(0.5)
    img_queue = dl.ImgQueue()
    img_queue.start_loaders(file_queue, num_threads=3, img_dir=IMG_DIR)
    img_queue.__repr__()
Beispiel #2
0
def test_lastbatch():
    # Test the status of the last_batch flag is working as expected
    file_queue = dl.FileQueue()
    file_queue.load_epochs(files, max_epochs=10)
    sleep(0.5)

    img_queue = dl.ImgQueue()
    img_queue.start_loaders(file_queue, num_threads=3, img_dir=IMG_DIR)
    sleep(1)

    # Get an entire epoch first
    data, labels = img_queue.get_batch(len(files))
    assert img_queue.last_batch
    assert not img_queue.last_batch

    # Get batches of 10 images and test the flag works
    num_batches = np.ceil(len(files) / 10).astype('int')
    for b in range(num_batches - 1):
        data, labels = img_queue.get_batch(10)
        assert not img_queue.last_batch
    data, labels = img_queue.get_batch(10)
    assert img_queue.last_batch

    # Get batches of 13 images and test the flag works
    num_batches = np.ceil(len(files) / 13).astype('int')
    for b in range(num_batches - 1):
        data, labels = img_queue.get_batch(13)
        assert not img_queue.last_batch
    data, labels = img_queue.get_batch(13)
    assert img_queue.last_batch
Beispiel #3
0
def test_imgqueue_nostart():
    # Test we get the right exception when we try to read from the image queue
    # without starting the loaders
    file_queue = dl.FileQueue()
    file_queue.load_epochs(files, max_epochs=1)
    sleep(0.5)

    img_queue = dl.ImgQueue()
    with pytest.raises(dl.ImgQueueNotStarted):
        img_queue.get_batch(1)
Beispiel #4
0
def test_imgqueue_epochreached():
    # Test we get the right exception when we've hit the sample limit
    file_queue = dl.FileQueue()
    file_queue.load_epochs(files, max_epochs=1)
    sleep(0.5)
    img_queue = dl.ImgQueue()
    img_queue.start_loaders(file_queue, num_threads=3, img_dir=IMG_DIR)
    sleep(0.5)
    img_queue.get_batch(batch_size=len(files))
    with pytest.raises(dl.FileQueueDepleted):
        img_queue.get_batch(1)
Beispiel #5
0
def test_imgqueue():
    # Test the imgqueue is working
    file_queue = dl.FileQueue()
    file_queue.load_epochs(files)
    sleep(0.5)

    img_queue = dl.ImgQueue()
    img_queue.start_loaders(file_queue, num_threads=3, img_dir=IMG_DIR)
    # Allow time to load in data
    sleep(1)
    img_queue.get_batch(100)
Beispiel #6
0
def test_imgqueue_lots():
    # Test we get the right behaviour when we try to read lots from the image
    # queue without letting it fill up
    file_queue = dl.FileQueue()
    file_queue.load_epochs(files)
    sleep(0.5)

    img_queue = dl.ImgQueue()
    img_queue.start_loaders(file_queue, num_threads=3, img_dir=IMG_DIR)

    img_queue.get_batch(1000)
    img_queue.get_batch(1000)
Beispiel #7
0
def test_imgqueue_loadersalive():
    file_queue = dl.FileQueue(maxsize=10)
    file_queue.load_epochs(files, max_epochs=1)
    sleep(0.5)
    assert file_queue.filling
    img_queue = dl.ImgQueue(maxsize=10)
    img_queue.start_loaders(file_queue, num_threads=3, img_dir=IMG_DIR)
    sleep(1)
    assert not img_queue.loaders_finished
    assert img_queue.filling
    img_queue.join_loaders()
    assert not file_queue.filling
    assert not img_queue.filling
    assert img_queue.loaders_finished
Beispiel #8
0
def test_transform():
    # Test we get the right behaviour when we try to read lots from the image
    # queue without letting it fill up
    file_queue = dl.FileQueue()
    file_queue.load_epochs(files)
    sleep(0.5)

    img_queue = dl.ImgQueue()

    def transform(x):
        return x - np.mean(x)

    img_queue.start_loaders(file_queue,
                            num_threads=3,
                            img_dir=IMG_DIR,
                            transform=transform)

    data, labels = img_queue.get_batch(10)
    for im in data:
        assert abs(np.mean(im)) <= 0.0001