hasdata - Determine if minibatchqueue can return mini-batch - MATLAB (original) (raw)
Main Content
Determine if minibatchqueue can return mini-batch
Since R2020b
Syntax
Description
[tf](#mw%5Ffd7bc4b4-a420-4352-9059-d48b00c33cf2) = hasdata([mbq](#mw%5Ff7fcc6be-12b3-493d-a466-ace18d0f9416%5Fsep%5Fmw%5F1052debc-abad-4547-9b2c-423b954fdb8a))
returns1
(true
) if mbq
can return a mini-batch using the next function, and 0
(false
) otherwise.
Use hasdata
in combination with next
to iterate over all data in the minibatchqueue
object. You can callnext
on a minibatchqueue
object until all data is returned. If mini-batches of data are still available in the minibatchqueue
object,hasdata
returns 1
. When you reach the end of the data, hasdata
returns 0
. Then, use reset orshuffle to reset the minibatchqueue
object and continue obtaining mini-batches withnext
.
Examples
Iterate Over All Mini-Batches
Use hasdata
with a while
loop to iterate over all data in the minibatchqueue
object.
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'}
While data is still available in the minibatchqueue
object, obtain the next mini-batch.
while hasdata(mbq) X = next(mbq) end
The loop ends when hasdata
returns false, and all mini-batches are returned.
Output Arguments
tf
— True or false result
1
| 0
True or false result, returned as a 1
or 0
of data type logical.
Version History
Introduced in R2020b