nets.data.iterator — nets 0.1 documentation

Table of Contents
Shortcuts

# Source code for nets.data.iterator

    """
    This modules defines how the data should be called from a datasets.
    This takes into account ``shuffle`` mode.
    """

    import numpy as np
    import nets
    from .batch import Batch

    class Iterator(object):
        r"""
        An ``Iterator`` call the data in batches. These batches can be shuffled and normalized.
        Usually, you want to feed a model with these batches.
        """

        def __init__(self, dataset, batch_size=32, shuffle=False):
            self.dataset = dataset
            self.batch_size = batch_size
            self.shuffle = shuffle

        def __iter__(self):
            starts = np.arange(0, len(self.dataset), self.batch_size)

            if self.shuffle:
                np.random.shuffle(list(self.dataset))

            for start in starts:
                end = start + self.batch_size
                batch_size = min(end, len(self.dataset)) - start
                yield Batch(self.dataset[start:end], batch_size)

        def __len__(self):
            return len(self.dataset) // self.batch_size

## Docs

Access comprehensive developer documentation for Nets

View Docs

## Tutorials

Get beginners tutorials and create state-of-the-art models

View Tutorials

## Resources

Check the GitHub page and contribute to the project

View GitHub

To analyze traffic and optimize your experience, we serve cookies on this site. By clicking or navigating, you agree to allow our usage of cookies. As the current maintainers of this site, Facebook’s Cookies Policy applies. Learn more, including about available controls: Cookies Policy.