How do I get filenames (and order) from DataBunch created by from folder?

I created this dataset from a path:

    real_data = ImageDataBunch.from_folder(path, ds_tfms=get_transforms(do_flip=False), 
                                      bs=bs,size=sz,train='TRAINSTAM_100img',test='REAL_DATA_TEST_CROPPED',resize_method=ResizeMethod.SQUISH)

In REAL_DATA_TEST_CROPPED, I have 11 images

I created and trained a learner, and ran TTA over my testset

pred_test_TTA, y_test_TTA = learn_for_real_data.TTA(ds_type=DatasetType.Test)
classes_real=np.argmax(pred_test, axis=1)

that gives me the following tensor of classes ID for my test set

tensor([1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1])

How can I know the filenames order in the test dataset so that I can know which images from the test set have class 0, and which have class 1?

I have seen in the forum I could you
real_data.test_dl.dataset.x

but it just gives me

ImageList (11 items)
Image (3, 47, 111),Image (3, 46, 109),Image (3, 75, 148),Image (3, 36, 125),Image (3, 69, 140)
Path: /Data/PROJECTS/Private/classifier_k/DATA/10K_SETS

I want the filenames and don’t know how to get it.
I have also seen answers with.fnames, but not working in my case.

Any help would be appreciated.

1 Like

Hey chum.

Try real_data.classes to know what 0 and 1 stands for.

data.items should get you what you want.

:wink:

2 Likes

For the classes it was ok.
For the filenames, indeed,real_data.test_dl.dataset.items gave me what I wanted

Thanks++

3 Likes

Try real_data.items. It might work just as well.

No, real_data.items gives the same as real_data.train_dl.dataset.items (probably shortcut default behaviour)
I had to specify to access the files from the test set

1 Like