Have you used if __name__ == '__main__': to protect your main function? More details here 130. You can also try to run the script in command prompt. If the error persists, then you can try to set num_worker of DataLoader to zero.