Randomizing validation set out of image folders

On Lesson 2, Jeremy uses get_csv_idxs to randomize images he uses for the validation set.

My question is: is there a way to randomize the validation images out of the folder structure we’re shown first, instead of the csv?

Thank you in advance.

similar query, i have an image data set, but all images are in their respective class folder, not separated into train and valid directories.
Is there a way to do it automatically or do I need to manually choose valid and train images.

maybe I’ve missed somehing, but the function I think Jeremy uses is get_cv_idxs(n), which in its basic usage only returns a list of randomized indexes between 0 and n.

function doc:
def get_cv_idxs(n, cv_idx=0, val_pct=0.2, seed=42):
“”" Get a list of index values for Validation set from a dataset

    n : int, Total number of elements in the data set.
    cv_idx : int, starting index [idx_start = cv_idx*int(val_pct*n)] 
    val_pct : (int, float), validation set percentage 
    seed : seed value for RandomState
    list of indexes 

you can explore the code yourself at:

Here are the scripts you can use to randomly separate the image set automatically.