Main Content

hasdata

Determine if minibatchqueue can return a mini-batch

    Description

    example

    tf = hasdata(mbq) returns 1 (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. You can call next on a minibatchqueue until all data is returned. If there are still mini-batches of data available in the minibatchqueue, hasdata returns 1. When you reach the end of the data, hasdata returns 0. Then, use reset or shuffle to reset the minibatchqueue and continue obtaining mini-batches with next.

    Examples

    collapse all

    Use hasdata with a while loop to iterate over all data in the minibatchqueue.

    Create a minibatchqueue 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'
        DispatchInBackground: 0
    
       Outputs:
                  OutputCast: {'single'}
             OutputAsDlarray: 1
             MiniBatchFormat: {''}
           OutputEnvironment: {'auto'}
    

    While there is still data available in the minibatchqueue, obtain the next mini-batch.

    while hasdata(mbq)
        X = next(mbq)
    end

    The loop ends when hasdata returns false, and all mini-batches have been returned.

    Input Arguments

    collapse all

    Queue of mini-batches, specified as a minibatchqueue object.

    Output Arguments

    collapse all

    True or false result, returned as a 1 or 0 of data type logical.

    Introduced in R2020b