Question on ImageFolder?

Hello, Actually, there are two folder on kaggle on path “’…/input/aptos2019-blindness-detection/”, train_images and test_images, and imageFolder is loading the all images from both folder but i want dataset from train folder only, please help how can i achieve this?
if i give path to tain_images, it gives error i.e:

RuntimeError: Found 0 files in subfolders of: …/input/aptos2019-blindness-detection/train_images
Supported extensions are: .jpg,.jpeg,.png,.ppm,.bmp,.pgm,.tif,.tiff,.webp

but if i give path: “…/input/aptos2019-blindness-detection/”, it reads images from both folder.

i can’t even create a new folder because data is read only in kaggle

Hello,

If you look at the documentation of ImageFolder, it specifies that it expects more than one folder in the specified location (root parameter), and not a folder containing only images.

What you could do, in your case, is load “…/input/aptos2019-blindness-detection/” which I presume contains both the training and testing folder. You can then split manually to keep only the training data. I wrote this piece of code to show how you could do that, but you will have to change the names of certain folders.

    root = '/store/dabeaq/datasets/middlebury/'
    folder = ImageFolder(root)
    print(folder.imgs)
    # [('/store/dabeaq/datasets/middlebury/cones/disp2.png', 0), ('/store/dabeaq/datasets/middlebury/cones/disp6.png', 0), ('/store/dabeaq/datasets/middlebury/cones/im2.png', 0), ('/store/dabeaq/datasets/middlebury/cones/im6.png', 0), ('/store/dabeaq/datasets/middlebury/other_cones/disp2_t.png', 1), ('/store/dabeaq/datasets/middlebury/other_cones/disp6_t.png', 1), ('/store/dabeaq/datasets/middlebury/other_cones/im2_t.png', 1), ('/store/dabeaq/datasets/middlebury/other_cones/im6_t.png', 1)]
    train_folder_id = folder.class_to_idx['cones']
    test_folder_id = folder.class_to_idx['other_cones']
    train_images = [img for img, i in folder.imgs if i == train_folder_id]
    test_images = [img for img, i in folder.imgs if i == test_folder_id]
    print(train_images)
    # ['/store/dabeaq/datasets/middlebury/cones/disp2.png', '/store/dabeaq/datasets/middlebury/cones/disp6.png', '/store/dabeaq/datasets/middlebury/cones/im2.png', '/store/dabeaq/datasets/middlebury/cones/im6.png']
    print(test_images)
    # ['/store/dabeaq/datasets/middlebury/other_cones/disp2_t.png', '/store/dabeaq/datasets/middlebury/other_cones/disp6_t.png', '/store/dabeaq/datasets/middlebury/other_cones/im2_t.png', '/store/dabeaq/datasets/middlebury/other_cones/im6_t.png']

Hope this is clear!

Thanks for the solution,i got it