PyTorch出现:RuntimeError: An attempt has been made to start a new process...报错

1.查看显卡:

第一步:同时按下键盘的win+r键,输入cmd

第二步:随后输入

python 复制代码
nvidia-smi

2.查看下载安装的包:

conda list

python 复制代码
conda list

3.问题报错

PyTorch出现:RuntimeError: An attempt has been made to start a new process...报错

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.

出错原因:网上查找结果,原因是多进程的原因

解决方法:

  1. 代码在运行 epoch 之前,加上 if __name__=='__main__'

2, 不使用多线程,即去掉 num_workers 参数,或设置 num_workers=0。

python 复制代码
dataset = torch.utils.data.DataLoader(trainset, batch_size=opt.batch_size,
                                        shuffle=True, num_workers=0, drop_last=True)
相关推荐
用户5191495848452 分钟前
Apache服务器自动化运维与安全加固脚本详解
人工智能·aigc
yintele8 分钟前
智能AI汽车电子行业,EMS应用相关问题
人工智能·汽车
却道天凉_好个秋15 分钟前
深度学习(四):数据集划分
人工智能·深度学习·数据集
数字冰雹19 分钟前
“图观”端渲染场景编辑器
人工智能·编辑器
里昆19 分钟前
【AI】Tensorflow在jupyterlab中运行要注意的问题
人工智能·python·tensorflow
荼蘼40 分钟前
OpenCV 高阶 图像金字塔 用法解析及案例实现
人工智能·opencv·计算机视觉
Clownseven43 分钟前
2025云计算趋势:Serverless与AI大模型如何赋能中小企业
人工智能·serverless·云计算
2401_8288906444 分钟前
使用 BERT 实现意图理解和实体识别
人工智能·python·自然语言处理·bert·transformer
Cheney8221 小时前
华为Ai岗机考20250903完整真题
人工智能·华为
新智元1 小时前
=COPILOT() 函数横空出世!AI 自动写公式效率起飞,网友:让 Excel 再次伟大
人工智能·openai