解决方法有两个:
方案1:定位到d2l文件夹下的torch.py文件,找到 get_dataloader_workers() 函数:
# Defined in file: ./chapter_linear-networks/image-classification-dataset.md
def get_dataloader_workers():
"""Use 4 processes to read the data."""
return 4
将上述函数修改为:
# Defined in file: ./chapter_linear-networks/image-classification-dataset.md
def get_dataloader_workers():
"""Use 0 processes to read the data."""
return 0
方案2:在项目中加入 if __name__ == "__main__": 语句,如下为本人的调用方法:
if __name__ == "__main__":
print(evaluate_accuracy(net, test_iter))
参考文章:https://blog.csdn.net/m0_55868614/article/details/123651223