0

I was following a Pytorch tutorial on Youtube, and when importing the relevant content/libraries, this was the code that the guy wrote:

import torchvision
from torchvision import transforms, datasets

My question is: Why do I need to explicitly type the second line? Didn't the first one import transforms and datasets already?

The video I was watching for reference: https://www.youtube.com/watch?v=i2yPxY2rOzs

I appreciate any help, and I'm sorry if this question is too obvious.

MWB
  • 11,740
  • 6
  • 46
  • 91
Ross
  • 1
  • 1
  • 3
    The second import makes `transforms` a shortcut for `torchvision.transforms` and `datasets` a shortcut for `torchvision.datasets`. – mkrieger1 Sep 21 '21 at 20:35

1 Answers1

2

You do not need to import them both. You are right, the first import will get the entire library, but the second one is used as a syntax sugaring to be able to refer to the transforms and datasets objects directly, instead of referring to them as "torchvision.transforms" or "torchvision.datasets".