PyTorch出現:RuntimeError: An attempt has been made to start a new process...報錯 (已解決)
PyTorch出現:RuntimeError: An attempt has been made to start a new process...報錯 (已解決)
最近從新除錯一段pytorch 程式碼,以前的伺服器上完全沒問題,但換了一臺機器,重新安裝了新版本的 cuda,anaconda,pytorch 等,以前的程式碼出現各種版本不適合的問題。一天下來,解決了 n 個問題。
問題:
現在說說這個問題。執行 pytorch 時出現的情況如下:
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.
原因:
網上查詢結果,原因是多程式的原因。具體可參考博文:Python 中的 if __name__ == '__main__' 該如何理解。
解決方法:
既然是多執行緒的原因,那麼可以從兩個角度解決問題:
1. 程式碼在執行 epoch
之前,加上 if __name__=='__main__'
試過,有效,一次通過。
2. 不使用多執行緒,即去掉 num_workers 引數,或設定 num_workers=0。
(目前還沒試過,因為我還是想用多執行緒。)
相關文章
- RuntimeError: An attempt has been made to start a new process before the current process hasError
- PyTorch出現錯誤“RuntimeError: Found dtype Double but expected Float”PyTorchError
- has been blocked by CORS policy跨域問題解決BloCCORS跨域
- YOLOv5-6.0訓練出錯及解決方法(RuntimeError)YOLOError
- 怎麼會出現 Cannot forward after response has been committed???ForwardMIT
- 【已解決】報錯 NVIDIA-SMI has failed because it couldn‘t communicate with the NVIDIA driverAI
- springcloudconfig訪問gitee報錯:Authentication is required but no CredentialsProvider has been registeredSpringGCCloudGiteeUIIDE
- PHP Warning: exec() has been disabled for security 問題解決辦法PHP
- java.lang.IllegalStateException: getOutputStream() has already been called for this response解決方案JavaException
- Hadoop出現 native snappy library not available: SnappyCompressor has not been loaded的解決辦法HadoopAPPAI
- New start new hope!
- getOutputStream() has already been called
- A New Start
- the new start
- Spring宣告式事務報錯"Transaction rolled back because it has been marked as rollback-only"分析...Spring
- service mysql start出錯,mysql啟動不了,解決mysql: unrecognized service錯誤MySqlZed
- 解決E: Package ‘libmysqlclient-dev‘ has no installation candidate報錯PackageIBMMySqlclientdev
- svn“Previous operation has not finished; run ‘cleanup‘ if it was interrupted“報錯的解決方法
- Testng results報告出現中文亂碼和更新maven出現報錯現象實戰解決Maven
- 解決MySQL server has gone away錯誤的解決方案MySqlServerGo
- JIRA startup failed, JIRA has been locked.AI
- InnoDB Plugin has been upgraded to version 1.0.8Plugin
- 【青春】farewell and new start
- Teamcenter 《POM has not start》處理
- 這個問題如何解決?Cannot forward after response has been committedForwardMIT
- 報錯(已解決)Command timed out after no timeout
- 前端base64圖片下載報錯(已解決!!!)前端
- 九月,NEW START
- Ubuntu20.04出現段錯誤核心已轉儲問題解決方案Ubuntu
- centos 老出現You have new mail in /var/spool/mail/root 解決CentOSAI
- Uncaught SyntaxError: Identifier 'Geometry' has already been declaredErrorIDE
- An unexpected error has been detected by Java Runtime EnvironmentErrorJava
- 【HMS Core】ToolKit,Merchant Service has not been enabled yet
- Transaction rolled back because it has been marked as rollback-only
- idea使用svn “Previous operation has not finished; run 'cleanup' if it was interrupted“報錯的解決方法Idea
- java.lang.IllegalStateException: Cannot call sendError() after the response has been committed解讀JavaExceptionErrorMIT
- FTPS“嚴重錯誤: gnutls_handshake: A TLS fatal alert has been received.”FTPTLS
- Eclipse出現"Running Android Lint has encountered a problem"解決方案EclipseAndroid