shuffle - Shuffle data in minibatchqueue - MATLAB (original) (raw)
Main Content
Shuffle data in minibatchqueue
Since R2020b
Syntax
Description
shuffle([mbq](#mw%5F78b30cfd-7a9c-44d3-8fef-a45745547171%5Fsep%5Fmw%5F1052debc-abad-4547-9b2c-423b954fdb8a))
resets the data held inmbq
and shuffles it into a random order. After shuffling, the next function returns different mini-batches. Use this syntax to reset and shuffle your data after each training epoch in a custom training loop.
Examples
Differences Between shuffle
and reset
The shuffle
function resets and shuffles theminibatchqueue
object so that you can obtain data from it in a random order. By contrast, the reset
function resets theminibatchqueue
object to the start of the underlying datastore.
Create a minibatchqueue
object from a datastore.
ds = digitDatastore; mbq = minibatchqueue(ds,MiniBatchSize=256)
mbq = minibatchqueue with 1 output and properties:
Mini-batch creation: MiniBatchSize: 256 PartialMiniBatch: 'return' MiniBatchFcn: 'collate' PreprocessingEnvironment: 'serial'
Outputs: OutputCast: {'single'} OutputAsDlarray: 1 MiniBatchFormat: {''} OutputEnvironment: {'auto'}
Obtain the first mini-batch of data.
Iterate over the rest of the data in the minibatchqueue
object. Usehasdata
to check if data is still available.
while hasdata(mbq) next(mbq); end
Shuffle the minibatchqueue
object and obtain the first mini-batch after the queue is shuffled.
shuffle(mbq); X2 = next(mbq);
Iterate over the remaining data again.
while hasdata(mbq) next(mbq); end
Reset the minibatchqueue
object and obtain the first mini-batch after the queue is reset.
reset(mbq); X3 = next(mbq);
Check whether the mini-batches obtained after resetting or shuffling theminibatchqueue
object are the same as the first mini-batch after the minibatchqueue
object is created.
isequal(X1,X2) isequal(X1,X3)
The reset
function returns the minibatchqueue
object to the start of the underlying data, so that the next
function returns mini-batches in the same order each time. By contrast, theshuffle
function shuffles the underlying data and produces randomized mini-batches.
Version History
Introduced in R2020b