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)
相关推荐
renhongxia112 分钟前
世界模型的四个商业场景:自动驾驶、机器人、内容产业与工业仿真
人工智能·机器人·自动驾驶
stormzhangV23 分钟前
AI 的玩法,该做减法了
人工智能·ai编程·claude
IT_陈寒33 分钟前
SpringBoot自动配置坑了我一周,原来问题这么蠢!
前端·人工智能·后端
糯米导航1 小时前
实践教程|搭建电商 AI 无限画布,实现百款商品主图自动化批量生成
运维·人工智能·自动化
朴马丁1 小时前
从制造到智造:PLM如何赋能企业研发创新
大数据·运维·人工智能·食品行业·流程行业plm·化工新材料行业·新能源材料行业
武子康1 小时前
GAIA、Cosmos、Genie 等视频模型纷纷自称"世界模型",为什么说视觉逼真度不构成决策证据?
人工智能·llm·agent
上海锝秉工控1 小时前
普通编码器:基础信号处理与数据转换核心岗
人工智能·信号处理
chenyuhao20242 小时前
第一章_自动驾驶中的社会交互
人工智能·机器学习·自动驾驶
洛阳泰山2 小时前
别再为做 AI 去学 Python 了!MaxKB4j:纯 Java 造的企业级 RAG + 工作流引擎,开箱即用
人工智能·开源·agent
fthux2 小时前
GitZip Pro:给GitHub仓库“瘦身”的魔法剪刀手
人工智能·chrome·ai·语言模型·开源·github·open source