Error while running Pytorch DataLoading tutorial

You could add this line at the bottom of your code, if you wrap the other code into the run() function.
Alternatively, you could wrap your whole code into the if-statement.
The important point is, that your main code should be executed inside this if-statement.
Otherwise Windows will execute the whole script, which will create processes recursively.
Example:

import torch
...

def run():
    model = ...
    # training
    for batch_idx, (data, target) in enumerate(loader):
        ...

if __name__=='__main__':
    run()
1 Like