RuntimeError: DataLoader worker (pid(s) 24632, 26892, 10480, 2964) exited unexpectedly
错误提示:
错误原因:torch.utils.data.DataLoader中的num_workers错误将num_workers改为0即可,0是默认值。num_workers是用来指定开多进程的数量,默认值为0,表示不启用多进程。若:将num_workers设置为0,程序报错,并提示设置环境变量KMP_DUPLICATE_LIB_OK=TRUE那你可以在设置环境变量KMP_DUPLICATE_LIB_OK=TRUE或者使用临时环境变量:(在代码开始处添加这行代码)
os.environ['KMP_DUPLICATE_LIB_OK'] = 'TRUE'
原代码:
# Training dataset train_loader = torch.utils.data.DataLoader( datasets.MNIST(root='.', train=True, download=True, transform=transforms.Compose([ transforms.ToTensor(), transforms.Normalize((0.1307,), (0.3081,)) ])), batch_size=64, shuffle=True, num_workers=4) # Test dataset test_loader = torch.utils.data.DataLoader( datasets.MNIST(root='.', train=False, transform=transforms.Compose([ transforms.ToTensor(), transforms.Normalize((0.1307,), (0.3081,)) ])), batch_size=64, shuffle=True, num_workers=4)
修改代码:
# Training dataset train_loader = torch.utils.data.DataLoader( datasets.MNIST(root='.', train=True, download=True, transform=transforms.Compose([ transforms.ToTensor(), transforms.Normalize((0.1307,), (0.3081,)) ])), batch_size=64, shuffle=True, num_workers=0) # Test dataset test_loader = torch.utils.data.DataLoader( datasets.MNIST(root='.', train=False, transform=transforms.Compose([ transforms.ToTensor(), transforms.Normalize((0.1307,), (0.3081,)) ])), batch_size=64, shuffle=True, num_workers=0)
欢迎关注我的CSDN博客心系五道口,有问题请私信2395856915@qq.com