pub struct BatchSampler<S = SequentialSampler> {
pub sampler: S,
pub batch_size: usize,
pub drop_last: bool,
}
Expand description
Wraps another sampler to yield a mini-batch of indices.
§Arguments
sampler
- Base sampler.batch_size
- Size of mini-batch.drop_last
- Iftrue
, the sampler will drop the last batch if its size would be less thanbatch_size
.
§Examples:
use ai_dataloader::sampler::SequentialSampler;
use ai_dataloader::sampler::BatchSampler;
let dataset = vec![0, 1, 2, 3];
let batch_sampler = BatchSampler {
sampler: SequentialSampler {
data_source_len: dataset.len(),
},
batch_size: 2,
drop_last: false,
};
let mut iter = batch_sampler.iter();
assert_eq!(iter.next(), Some(vec![0, 1]));
assert_eq!(iter.next(), Some(vec![2, 3]));
Fields§
§sampler: S
Base sampler.
batch_size: usize
Size of mini batch.
drop_last: bool
If true
, the sampler will drop the last batch if
its size were less than batch_size
.
Implementations§
Source§impl<S: Sampler> BatchSampler<S>
impl<S: Sampler> BatchSampler<S>
Sourcepub fn iter(&self) -> BatchIterator<S::IntoIter> ⓘ
pub fn iter(&self) -> BatchIterator<S::IntoIter> ⓘ
Return an iterator over the BatchSampler
.
Trait Implementations§
Source§impl<S: Clone> Clone for BatchSampler<S>
impl<S: Clone> Clone for BatchSampler<S>
Source§fn clone(&self) -> BatchSampler<S>
fn clone(&self) -> BatchSampler<S>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl<S: Debug> Debug for BatchSampler<S>
impl<S: Debug> Debug for BatchSampler<S>
Source§impl<S: Hash> Hash for BatchSampler<S>
impl<S: Hash> Hash for BatchSampler<S>
Source§impl<S: Sampler> IntoIterator for &BatchSampler<S>
impl<S: Sampler> IntoIterator for &BatchSampler<S>
Source§impl<S: Sampler> Len for BatchSampler<S>
impl<S: Sampler> Len for BatchSampler<S>
Source§impl<S: Ord> Ord for BatchSampler<S>
impl<S: Ord> Ord for BatchSampler<S>
Source§fn cmp(&self, other: &BatchSampler<S>) -> Ordering
fn cmp(&self, other: &BatchSampler<S>) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<S: PartialEq> PartialEq for BatchSampler<S>
impl<S: PartialEq> PartialEq for BatchSampler<S>
Source§impl<S: PartialOrd> PartialOrd for BatchSampler<S>
impl<S: PartialOrd> PartialOrd for BatchSampler<S>
impl<S: Eq> Eq for BatchSampler<S>
impl<S> StructuralPartialEq for BatchSampler<S>
Auto Trait Implementations§
impl<S> Freeze for BatchSampler<S>where
S: Freeze,
impl<S> RefUnwindSafe for BatchSampler<S>where
S: RefUnwindSafe,
impl<S> Send for BatchSampler<S>where
S: Send,
impl<S> Sync for BatchSampler<S>where
S: Sync,
impl<S> Unpin for BatchSampler<S>where
S: Unpin,
impl<S> UnwindSafe for BatchSampler<S>where
S: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more