ó šÄïYc@sUdZddlZddlmZddlmZd„Zdefd „ƒYZ dS( sDataset generator.iÿÿÿÿNi(tsampleri(tndcCsˆt|dtjƒr#tj|ŒSt|dtƒr_t|Œ}g|D]}t|ƒ^qIStj|ƒ}tj |d|j ƒSdS(sCollate data into batch.itdtypeN( t isinstanceRtNDArraytstackttupletzipt _batchifytnptasarraytarrayR(tdatati((s;build/bdist.linux-armv7l/egg/mxnet/gluon/data/dataloader.pyRs  t DataLoadercBs8eZdZdedddd„Zd„Zd„ZRS(s½Loads data from a dataset and returns mini-batches of data. Parameters ---------- dataset : Dataset Source dataset. Note that numpy and mxnet arrays can be directly used as a Dataset. batch_size : int Size of mini-batch. shuffle : bool Whether to shuffle the samples. sampler : Sampler The sampler to use. Either specify sampler or shuffle, not both. last_batch : {'keep', 'discard', 'rollover'} How to handle the last batch if batch_size does not evenly divide `len(dataset)`. keep - A batch with less samples than previous batches is returned. discard - The last batch is discarded if its incomplete. rollover - The remaining samples are rolled over to the next epoch. batch_sampler : Sampler A sampler that returns mini-batches. Do not specify batch_size, shuffle, sampler, and last_batch if batch_sampler is specified. cCsñ||_|dkr«|dkr0tdƒ‚n|dkrr|rZtjt|ƒƒ}q‡tjt|ƒƒ}n|r‡tdƒ‚ntj|||rŸ|ndƒ}n9|dk sÕ|sÕ|dk sÕ|dk rätdƒ‚n||_dS(Ns>batch_size must be specified unless batch_sampler is specifieds5shuffle must not be specified if sampler is specifiedtkeeps`batch_size, shuffle, sampler and last_batch must not be specified if batch_sampler is specified.( t_datasettNonet ValueErrort_samplert RandomSamplertlentSequentialSamplert BatchSamplert_batch_sampler(tselftdatasett batch_sizetshuffleRt last_batcht batch_sampler((s;build/bdist.linux-armv7l/egg/mxnet/gluon/data/dataloader.pyt__init__As      ccs=x6|jD]+}tg|D]}|j|^qƒVq WdS(N(RRR(Rtbatchtidx((s;build/bdist.linux-armv7l/egg/mxnet/gluon/data/dataloader.pyt__iter__ZscCs t|jƒS(N(RR(R((s;build/bdist.linux-armv7l/egg/mxnet/gluon/data/dataloader.pyt__len__^sN(t__name__t __module__t__doc__RtFalseRR"R#(((s;build/bdist.linux-armv7l/egg/mxnet/gluon/data/dataloader.pyR(s   ( R&tnumpyR tRRRRtobjectR(((s;build/bdist.linux-armv7l/egg/mxnet/gluon/data/dataloader.pyts