class MXNet::Gluon::Data::BatchSampler(T)

Overview

Wraps another Sampler and returns mini-batches of samples.

sampler = MXNet::Gluon::Data::BatchSampler.new(
  MXNet::Gluon::Data::SequentialSampler.new(10), 3, :keep
)
sampler.to_a # => [[0, 1, 2], [3, 4, 5], [6, 7, 8], [9]]

Included Modules

Defined in:

mxnet/gluon/data/sampler.cr

Constructors

Instance Method Summary

Instance methods inherited from class MXNet::Gluon::Data::Sampler(Array(T))

each(&block : T(T) -> _)
each
each
, size size

Constructor Detail

def self.new(sampler : Sampler(T), batch_size : Int32, last_batch = :keep) #

Creates a new instance.

Parameters

  • sampler (Sampler) The source sampler.
  • batch_size (Int32) Size of mini-batches.
  • last_batch (:keep, :discard, :rollover) Specifies how the last batch is handled if batch_size does not evenly divide sampler sequence size. If :keep, the last batch will be returned directly, but will contain fewer elements than batch_size requires. If :discard, the last batch will be discarded. If :rollover, the remaining elements will be rolled over to the next iteration.

[View source]

Instance Method Detail

def next #

Returns the next element in the sequence, or Iterator::Stop::INSTANCE if there are no more elements.


[View source]
def rewind #

Rewinds the sequence.

If the source sampler is a BatchSampler, this rewinds it as well.


[View source]
def size #

Returns the number of elements in the sequence.


[View source]