How can I access the label categories from a DataLoaders object?

My code looks like this:

normalize_tfm = Normalize.from_stats(*imagenet_stats)
block = DataBlock(
    get_items=get_image_files,
    get_y=parent_label,
    blocks=(ImageBlock, CategoryBlock ),
    splitter=splitter,
    batch_tfms=normalize_tfm,
)
dls = block.dataloaders(root_dir/'4_states', batch_size=64)

I have made a model, and I would like to convert its predictions from a number (eg. 0) to a string (eg. “Hawaii”). I think I need to access the categories created by the CategoryBlock to get this information. How can I do this?

dls.vocab

2 Likes