import torchvision
from torchvision import transforms
train_data_path="./train/"
transforms = transforms.Compose([
transforms.Resize(64),
transforms.ToTensor(),
transforms.Normalize(mean=[0.485, 0.456, 0.406],
std=[0.229, 0.224, 0.225] )
])
train_data = torchvision.datasets.ImageFolder
(root=train_data_path,transform=transforms)
这是错误消息:
File "<ipython-input-4-e470172b3902>", line 8
    (root=train_data_path,transform=transforms)
         ^
SyntaxError: invalid syntax
我将如何解决这个问题?

最佳答案

您需要将右括号直接连接到函数,而没有任何空格将它们分隔开。尝试将最后两行替换为:

train_data = torchvision.datasets.ImageFolder(
    root=train_data_path, transform=transforms
)

关于python - 在PyTorch中将root =设置为时,语法无效,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/62567073/

10-12 17:52