Main Content

hasdata

Determine if minibatchqueue can return 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 object. You can call next 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 or shuffle to reset the minibatchqueue object and continue obtaining mini-batches with next.

    Examples

    collapse all

    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'
        DispatchInBackground: 0
    
       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.

    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