NameError: name 'transforms' is not defined, while using google colab
NameError: name 'transforms' is not defined, while using google colab
train = datasets.MNIST("", train=True, download=True,transform = transforms.Compose([transforms.ToTensor()]))
test = datasets.MNIST("", train=False, download=True,transform = transforms.Compose([transforms.ToTensor()]))`
在 colab notebook 上执行此操作后,出现此错误:
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*
根据上下文我猜你正在使用 Pytorch,在这种情况下你需要确保你有:
from torchvision import transforms
在你的导入中。从外观上看,您已经从同一个库中导入了 datasets
。
train = datasets.MNIST("", train=True, download=True,transform = transforms.Compose([transforms.ToTensor()]))
test = datasets.MNIST("", train=False, download=True,transform = transforms.Compose([transforms.ToTensor()]))`
在 colab notebook 上执行此操作后,出现此错误:
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*
根据上下文我猜你正在使用 Pytorch,在这种情况下你需要确保你有:
from torchvision import transforms
在你的导入中。从外观上看,您已经从同一个库中导入了 datasets
。