Struct ai_dataloader::sampler::BatchSampler
source · [−]pub struct BatchSampler<S: Sampler = 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: SBase sampler.
batch_size: usizeSize of mini batch.
drop_last: boolIf true, the sampler will drop the last batch if
its size were less than batch_size.
Implementations
sourceimpl<S: Sampler> BatchSampler<S>
impl<S: Sampler> BatchSampler<S>
sourcepub fn iter(&self) -> BatchIterator<S::IntoIter>ⓘNotable traits for BatchIterator<I>impl<I> Iterator for BatchIterator<I>where
I: Iterator<Item = usize>, type Item = Vec<usize>;
pub fn iter(&self) -> BatchIterator<S::IntoIter>ⓘNotable traits for BatchIterator<I>impl<I> Iterator for BatchIterator<I>where
I: Iterator<Item = usize>, type Item = Vec<usize>;
I: Iterator<Item = usize>, type Item = Vec<usize>;
Return an iterator over the BatchSampler.
Trait Implementations
sourceimpl<S: Clone + Sampler> Clone for BatchSampler<S>
impl<S: Clone + Sampler> Clone for BatchSampler<S>
sourcefn clone(&self) -> BatchSampler<S>
fn clone(&self) -> BatchSampler<S>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moresourceimpl<S: Debug + Sampler> Debug for BatchSampler<S>
impl<S: Debug + Sampler> Debug for BatchSampler<S>
sourceimpl<S: Hash + Sampler> Hash for BatchSampler<S>
impl<S: Hash + Sampler> Hash for BatchSampler<S>
sourceimpl<S: Sampler> Len for BatchSampler<S>
impl<S: Sampler> Len for BatchSampler<S>
sourceimpl<S: Ord + Sampler> Ord for BatchSampler<S>
impl<S: Ord + Sampler> Ord for BatchSampler<S>
sourcefn cmp(&self, other: &BatchSampler<S>) -> Ordering
fn cmp(&self, other: &BatchSampler<S>) -> Ordering
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl<S: PartialEq + Sampler> PartialEq<BatchSampler<S>> for BatchSampler<S>
impl<S: PartialEq + Sampler> PartialEq<BatchSampler<S>> for BatchSampler<S>
sourcefn eq(&self, other: &BatchSampler<S>) -> bool
fn eq(&self, other: &BatchSampler<S>) -> bool
sourceimpl<S: PartialOrd + Sampler> PartialOrd<BatchSampler<S>> for BatchSampler<S>
impl<S: PartialOrd + Sampler> PartialOrd<BatchSampler<S>> for BatchSampler<S>
sourcefn partial_cmp(&self, other: &BatchSampler<S>) -> Option<Ordering>
fn partial_cmp(&self, other: &BatchSampler<S>) -> Option<Ordering>
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self and other) and is used by the <=
operator. Read moreimpl<S: Eq + Sampler> Eq for BatchSampler<S>
impl<S: Sampler> StructuralEq for BatchSampler<S>
impl<S: Sampler> StructuralPartialEq for BatchSampler<S>
Auto Trait Implementations
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
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more