We will start the process by preparing the dataset. As images are stored in different folders, we need to create a mapping between their path and class.
We do this by iterating over each and every folder and populating a tuple with a location of a photo and ID of the class. The resulting tuple is stored in the images array. We also shuffle the images array in the end to avoid images being ordered. Consider the following code:
using Images, MXNet, StatsBase
DATASET_DIR = "data/101_ObjectCategories"
CLASSES = readdir(DATASET_DIR)
images = Tuple{String,Int}[]
for dir_id = 1:length(CLASSES)
dir = CLASSES[dir_id]
all_files = readdir(joinpath(DATASET_DIR, dir))
keep_files = filter(x -> endswith(x, ".jpg"), all_files)
append!(images, map(x -> (joinpath(DATASET_DIR, dir, x), dir_id - 1), keep_files))
end
images = images[shuffle(1:length(images))];