Пример #1
0
def test_iterate_scheme():
    from fuel.datasets import IndexableDataset
    from fuel.schemes import (SequentialScheme, ShuffledScheme,SequentialExampleScheme, ShuffledExampleScheme)

    seed = 1234
    rng = numpy.random.RandomState(seed)
    features = rng.randint(256, size=(8, 2, 2))
    targets = rng.randint(4, size=(8, 1))

    dataset = IndexableDataset(indexables=OrderedDict([('features', features),
                                                       ('targets', targets)]),
                               axis_labels=OrderedDict([('features', ('batch', 'height', 'width')),
                                                        ('targets', ('batch', 'index'))]))

    schemes = [SequentialScheme(examples=8, batch_size=5),
               ShuffledScheme(examples=8, batch_size=3),
               SequentialExampleScheme(examples=8),
               ShuffledExampleScheme(examples=8)]

    # for scheme in schemes:
    #     print(list(scheme.get_request_iterator()))

    state = dataset.open()
    scheme = ShuffledScheme(examples=dataset.num_examples, batch_size=3)

    for request in scheme.get_request_iterator():
        data = dataset.get_data(state=state, request=request)
        print(data[0].shape, data[1].shape)

    dataset.close(state)
Пример #2
0
def test_indexabel_dataset():
    from fuel.datasets import IndexableDataset

    seed = 1234
    rng = numpy.random.RandomState(seed)
    features = rng.randint(256, size=(8, 2, 2))
    targets = rng.randint(4, size=(8, 1))

    dataset = IndexableDataset(indexables=OrderedDict([('features', features),
                                                       ('targets', targets)]),
                               axis_labels=OrderedDict([('features', ('batch', 'height', 'width')),
                                                        ('targets', ('batch', 'index'))]))

    state = dataset.open()
    print('State is {}.'.format(state))

    print(dataset.get_data(state=state, request=[1, 0]))

    dataset.close(state=state)