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
- springcloudconfig訪問gitee報錯:Authentication is required but no CredentialsProvider has been registeredSpringGCCloudGiteeUIIDE
- has been blocked by CORS policy跨域問題解決BloCCORS跨域
- 【已解決】報錯 NVIDIA-SMI has failed because it couldn‘t communicate with the NVIDIA driverAI
- YOLOv5-6.0訓練出錯及解決方法(RuntimeError)YOLOError
- PHP Warning: exec() has been disabled for security 問題解決辦法PHP
- 解決E: Package ‘libmysqlclient-dev‘ has no installation candidate報錯PackageIBMMySqlclientdev
- querydsl報錯: Attempt to recreate a file for type
- svn“Previous operation has not finished; run ‘cleanup‘ if it was interrupted“報錯的解決方法
- 報錯(已解決)Command timed out after no timeout
- 解決MySQL server has gone away錯誤的解決方案MySqlServerGo
- Uncaught SyntaxError: Identifier 'Geometry' has already been declaredErrorIDE
- Android gradle問題解決: This app has been built with an incorrect configuration. Please configure your b...AndroidGradleAPPUI
- Teamcenter 《POM has not start》處理
- Django Error: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissionsDjangoErrorORB
- 解決new Thread().Start導致高併發CPU 100%的問題thread
- vue專案啟動報錯(SyntaxError: Identifier ‘__vite__injectQuery’ has already been declared (at ${mod.id}:55030:1))VueErrorIDEVite
- 【HMS Core】ToolKit,Merchant Service has not been enabled yet
- Thread 1: Fatal error: init(coder:) has not been implementedthreadError
- The app.Configuration 'compile' is obsolete and has been replaced with 'implementation'APPCompile
- Testng results報告出現中文亂碼和更新maven出現報錯現象實戰解決Maven
- java.lang.IllegalStateException: Cannot call sendError() after the response has been committed解讀JavaExceptionErrorMIT
- 'This NSPersistentStoreCoordinator has no persistent stores 報錯
- pytorch執行錯誤:RuntimeError: a leaf Variable that requires grad is being used in an in-place operationPyTorchErrorUI
- react-解決 fetch 跨域問題:Access to fetch at XXX from origin YYY has been blocked by CORS policyReact跨域BloCCORS
- Ubuntu20.04出現段錯誤核心已轉儲問題解決方案Ubuntu
- FeignClientSpecification‘ could not be registered. A bean with that name has already been definedclientBean
- Transaction rolled back because it has been marked as rollback-only
- matplotlib使用時報錯RuntimeError: Python is not installed as a framework(一)ErrorPythonFramework
- React-App:NPM start 報錯ReactAPPNPM
- 用命令列啟動 docker 報錯:Redirecting to /bin/systemctl start docker.service 解決方法命令列Docker
- npm install報錯、失敗,出現network proxy問題解決方案NPM
- 前端base64圖片下載報錯(已解決!!!)前端
- Caused by: java.lang.IllegalStateException: getWriter() has already been called for this responseJavaException
- nginx出現403錯誤的解決方法Nginx
- 無法啟動homestead,出現報錯Your VM has become "inaccessible." 該怎麼辦?
- Laravel 安裝 voyager 出現的資料庫報錯問題解決Laravel資料庫