deep-learning-with-pytorch / dlwpt-code

Code for the book Deep Learning with PyTorch by Eli Stevens, Luca Antiga, and Thomas Viehmann.
https://www.manning.com/books/deep-learning-with-pytorch
4.69k stars 1.98k forks source link

Read labels from the module, not from some random file #103

Open simsong opened 1 year ago

simsong commented 1 year ago

Chapter 2 uses this code to get the model labels:

with open('../data/p1ch2/imagenet_classes.txt') as f:
    labels = [line.strip() for line in f.readlines()]

However, it is never made clear where the file imagenet_classes.txt comes from.

It turns out that they are already in torchvision.models:

from torchvision import models
labels = models.ResNet101_Weights.DEFAULT.meta['categories']

It would be useful to update the book to make this clear, or at least put it in the errata.