Here’s what the FastAI library API looks like:

Imagenette is a subset of ImageNet with 10 very different classes. Imagenet is mainly used to quickly experiment before trying a more fleshed-out technique on a full ImageNet dataset. We’ll show in this tutorial how to train a model on it, using high-level APIs, then going into the fastai library to show how to use the mid-level APIs we’ve designed.

Assemble the data

Loading the data with the data block API

We’ll start by using the get_image_files function to get all the images in subfolders:

fnames = get_image_files(path)

Let’s create an empty datablock:

dblock = DataBlock()
dsets = dblock.datasets(fnames)
dsets.train[0]

By default, the data block API assumes that we have an input and a target, which is why we see our filename repeated twice.

The first thing we can do is to use a get_items function to assemble our items inside the data block:

dblock = DataBlock(get_items = get_image_files)

The difference is that you then pass as a source the folder with the images and not all the filenames:

dsets = dblock.datasets(path)
dsets.train[0]

We need to prepare our target to be processed as an image:

parent_label(fnames[0])