Get all labels from mx.io.ImageRecordIter


#1

I would like to get all the labels from this object

test = mx.io.ImageRecordIter(
    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:
    print(type(test_batch))
    d, l = test_batch.data, test_batch.label
    la = l[0].asnumpy()
    print(la.shape)

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

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


#2

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.