Get all labels from

I would like to get all the labels from this object

test =
    path_imgrec = "chestxray/test.rec",
    data_shape = (3, HEIGHT, WIDTH),
    path_imglist = "chestxray/test.lst",
    label_width = 15,
    batch_size = BATCHSIZE,
    shuffle = False,
    rand_mirror = 0, #flip horizontally
    preprocess_threads = 24

I’m doing:

for test_batch in test:
    d, l =, test_batch.label
    la = l[0].asnumpy()

However, I don’t get the final batch correctly.

Is there a function that loads all the labels directly to memory?

Is the number of examples divisible by the batch size? If not you might want to set the round_batch parameter of ImageRecordIter depending on how you want to handle the last batch.