【Windows pytorch-gpu环境】RuntimeError: Attempt to start a new process before the current process has

简介: 【Windows pytorch-gpu环境】RuntimeError: Attempt to start a new process before the current process has

遇到的错误:

1. RuntimeError: 
2.             Attempt to start a new process before the current process
3.             has finished its bootstrapping phase.
4.             This probably means that you are on Windows and you have
5.             forgotten to use the proper idiom in the main module:
6.                 if __name__ == '__main__':
7.                     freeze_support()
8.                     ...
9.             The "freeze_support()" line can be omitted if the program
10.             is not going to be frozen to produce a Windows executable.

查阅:https://stackoverflow.com/questions/18204782/runtimeerror-on-windows-trying-python-multiprocessing

对应的解答:

On Windows the subprocesses will import (i.e. execute) the main module at start. You need to insert an if __name__ == '__main__': guard in the main module to avoid creating subprocesses recursively.

Modified testMain.py:

1. import parallelTestModule
2. 
3. if __name__ == '__main__':    
4.     extractor = parallelTestModule.ParallelExtractor()
5.     extractor.runInParallel(numProcesses=2, numThreads=4)

找到自己问题:

通过分析应该是系统的多线程问题

找到代码中使用到的多线程代码进行修改:

trainloader = DataLoader(db_train, batch_size=p['trainBatch'], shuffle=True, num_workers=2)

设置num_workers为0,也就是用主进程读取数据后,模型训练程序运行正常。

解答:

PyTorch——num_workers参数的设置

https://blog.csdn.net/songyuc/article/details/103365591

Soumith Chintala也在《Deep Learning with PyTorch: A 60 Minute Blitz》中说到过这个问题:

1. Soumith Chintala也在《Deep Learning with PyTorch: A 60 Minute Blitz》中说到过这个问题:
2. 
3. If running on Windows and you get a BrokenPipeError, try setting
4. the num_worker of torch.utils.data.DataLoader() to 0.

 

AIEarth是一个由众多领域内专家博主共同打造的学术平台,旨在建设一个拥抱智慧未来的学术殿堂!【平台地址:https://devpress.csdn.net/aiearth】 很高兴认识你!加入我们共同进步!

相关实践学习
基于阿里云DeepGPU实例,用AI画唯美国风少女
本实验基于阿里云DeepGPU实例,使用aiacctorch加速stable-diffusion-webui,用AI画唯美国风少女,可提升性能至高至原性能的2.6倍。
目录
相关文章
|
8天前
|
TensorFlow 算法框架/工具 C++
在有GPU的windows上安装TensorFlow
在有GPU的windows上安装TensorFlow
26 0
|
8天前
|
算法 Linux Windows
FFmpeg开发笔记(十七)Windows环境给FFmpeg集成字幕库libass
在Windows环境下为FFmpeg集成字幕渲染库libass涉及多个步骤,包括安装freetype、libxml2、gperf、fontconfig、fribidi、harfbuzz和libass。每个库的安装都需要下载源码、配置、编译和安装,并更新PKG_CONFIG_PATH环境变量。最后,重新配置并编译FFmpeg以启用libass及相关依赖。完成上述步骤后,通过`ffmpeg -version`确认libass已成功集成。
25 1
FFmpeg开发笔记(十七)Windows环境给FFmpeg集成字幕库libass
|
8天前
|
计算机视觉 Windows
OpenCV + CLion在windows环境下使用CMake编译, 出现Mutex相关的错误的解决办法
OpenCV + CLion在windows环境下使用CMake编译, 出现Mutex相关的错误的解决办法
19 0
|
8天前
|
Web App开发 JavaScript 前端开发
Windows环境下 NVM 介绍、下载安装及使用详解
Windows环境下 NVM 介绍、下载安装及使用详解
28 0
|
8天前
|
编解码 Linux Windows
FFmpeg开发笔记(十三)Windows环境给FFmpeg集成libopus和libvpx
本文档介绍了在Windows环境下如何为FFmpeg集成libopus和libvpx库。首先,详细阐述了安装libopus的步骤,包括下载源码、配置、编译和安装,并更新环境变量。接着,同样详细说明了libvpx的安装过程,注意需启用--enable-pic选项以避免编译错误。最后,介绍了重新配置并编译FFmpeg以启用这两个库,通过`ffmpeg -version`检查是否成功集成。整个过程参照了《FFmpeg开发实战:从零基础到短视频上线》一书的相关章节。
30 0
FFmpeg开发笔记(十三)Windows环境给FFmpeg集成libopus和libvpx
|
8天前
|
编解码 Linux Windows
FFmpeg开发笔记(十一)Windows环境给FFmpeg集成vorbis和amr
在Windows环境下,为FFmpeg集成音频编解码库,包括libogg、libvorbis和opencore-amr,涉及下载源码、配置、编译和安装步骤。首先,安装libogg,通过配置、make和make install命令完成,并更新PKG_CONFIG_PATH。接着,安装libvorbis,同样配置、编译和安装,并修改pkgconfig文件。之后,安装opencore-amr。最后,重新配置并编译FFmpeg,启用ogg和amr支持,通过ffmpeg -version检查是否成功。整个过程需确保环境变量设置正确,并根据路径添加相应库。
37 1
FFmpeg开发笔记(十一)Windows环境给FFmpeg集成vorbis和amr
|
8天前
|
安全 开发工具 git
Windows11搭建Python环境(2)- Anaconda虚拟环境中安装Git
Windows11搭建Python环境(2)- Anaconda虚拟环境中安装Git
41 0
|
8天前
|
SQL Shell 数据库
七天.NET 8操作SQLite入门到实战 - 第二天 在 Windows 上配置 SQLite环境
七天.NET 8操作SQLite入门到实战 - 第二天 在 Windows 上配置 SQLite环境
|
编译器 网络虚拟化 C语言
2023年最全 Windows + VSCode 配置 OpenCV C++ 一站式开发调试环境教程
2023年最全 Windows + VSCode 配置 OpenCV C++ 一站式开发调试环境教程
1198 0
|
7月前
|
开发工具 虚拟化 Windows
1.1 Windows驱动开发:配置驱动开发环境
在进行驱动开发之前,您需要先安装适当的开发环境和工具。首先,您需要安装`Windows`驱动开发工具包(WDK),这是一组驱动开发所需的工具、库、示例和文档。然后,您需要安装`Visual Studio`开发环境,以便编写和调试驱动程序。在安装WDK和`Visual Studio`之后,您还需要配置适当的项目设置,以便能够正确编译和构建驱动程序。首先我们需要安装`Visual Studio 2013`这款功能强大的程序开发工具,在课件内请双击`ISO`文件并运行内部的`vs_ultimate.exe`安装包,`Visual Studio`的安装非常的简单,您只需要按照提示全部选择默认参数即可,
149 1
1.1 Windows驱动开发:配置驱动开发环境

热门文章

最新文章