我看不到任何错误的代码部分,但错误继续发生 什么是BrokenPipeError?
我的代码在某人的环境中工作良好,但在我的环境中却无法工作。
import torch
import torchvision
import torchvision.transforms as transforms
import matplotlib.pyplot as plt
import numpy as np
transform = transforms.Compose([transforms.ToTensor(), transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])
# Load training dataset
trainset = torchvision.datasets.CIFAR10(root='.\\data', train=True, download=True, transform=transform)
trainloader = torch.utils.data.DataLoader(trainset, batch_size=4, shuffle=True, num_workers=2)
# Load test dataset
testset = torchvision.datasets.CIFAR10(root='.\\data', train=False, download=True, transform=transform)
testloader = torch.utils.data.DataLoader(testset, batch_size=4, shuffle=False, num_workers=2)
classes = ('plane', 'car', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck')
def imshow(img):
img = img / 2 + 0.5
npimg = img.numpy()
plt.imshow(np.transpose(npimg, (1, 2, 0)))
# Get train images randomly
dataiter = iter(trainloader)
images, labels = dataiter.next()
# Show images
imshow(torchvision.utils.make_grid(images))
# print name of labels
print(' '.join('%5s' % classes[labels[j]] for j in range(4)))
有人可以给我建议吗? 看来,部分加载CIFAR10数据集没有问题,但是之后,部分绘图图像会产生错误