RuntimeError:An attempt has been made to start a new process before the
运行python程序,训练RNN的时候出现:
RuntimeError:
An attempt has been made to start a new process before the
current process has finished its bootstrapping phase.
This probably means that you are not using fork to start your
child processes and you have forgotten to use the proper idiom
in the main module:
if __name__ == '__main__':
freeze_support()
...
The "freeze_support()" line can be omitted if the program
is not going to be frozen to produce an executable.
看了看程序中出错的位置:
File "C:\Developer\python\pythonProject\hw4\hw4_main.py", line 431, in <module>
training(batch_size, epoch, lr, model_dir, train_loader, val_loader, model, device)
File "C:\Developer\python\pythonProject\hw4\hw4_main.py", line 300, in training
for i, (inputs, labels) in enumerate(train):
我们定位到431行,加入一个main函数:
# 開始訓練
if __name__=="__main__":
training(batch_size, epoch, lr, model_dir, train_loader, val_loader, model, device)
"""### Predict and Write to csv file"""
因为多线程程序要放在主函数中训练。这样就不报错了。