D2L, the solution of runtimeerror: dataloader worker (pid(s) ) exited unexpectedly when using dataloader under Pytorch win10

        I use python3.8+pytorch1.11. The environment used in the course demonstration of Mr. Li Mu is linux and no error is reported, but under win10, it needs to be added before using the dataloader

if __name__ == "__main__":

For example:

batch_size = 256
if __name__ == "__main__":
    train_iter, test_iter = d2l.load_data_fashion_mnist(batch_size)

to run successfully

        There are other methods on the Internet to set num_worker to 0, and it can also run successfully in a single thread, but there is no corresponding parameter for the dataloader that directly imports d2l

Possible Causes:

        The program enables multi-threading at runtime, and the use of multi-threading uses the freeze_support() function.
The freeze_support() function can be run directly on linux and unix-like systems, and needs to be followed by main in windows systems.

Update: You can directly change the code in the package

        Find this file...\Anaconda\Lib\site-packages\d2l\torch.py
        ​​edit the def get_dataloader_workers():
        change to return 0

        或者return 0 if sys.platform.startswith('win') else 4

Guess you like

Origin blog.csdn.net/qq_52712475/article/details/129844275