3
train = datasets.MNIST("", train=True, download=True,transform = transforms.Compose([transforms.ToTensor()]))
test = datasets.MNIST("", train=False, download=True,transform = transforms.Compose([transforms.ToTensor()]))`

After executing this on colab notebook, I am getting this error:

Traceback (most recent call last)
<ipython-input-6-b81aa6cf1cbe> in <module>()
----> 1 train = datasets.MNIST("", train=True, download=True,transform = transforms.Compose([transforms.ToTensor()]))
      2 test = datasets.MNIST("", train=False, download=True,transform = transforms.Compose([transforms.ToTensor()]))

NameError: name 'transforms' is not defined*
1
  • 2
    Why do you think it should be defined? Did you import it? Commented May 17, 2020 at 18:43

1 Answer 1

12

I'm guessing from the context that you're using Pytorch, in which case you need to make sure you have:

from torchvision import transforms

In your imports. By the looks of things you have already imported datasets from the same library.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.