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)
相关推荐
白日做梦Q几秒前
Label Studio 安装与使用完整文档(可直接复制部署)
深度学习·yolo·计算机视觉
带娃的IT创业者1 分钟前
本地AI的觉醒:GitNexus如何让GenAI从云端走向你的口袋
人工智能·大模型·边缘计算·开源项目·genai·本地ai·gitnexus
火山引擎开发者社区20 分钟前
龙虾突然“罢工”?别慌,我们派出了“AI 医生”
人工智能
NQBJT24 分钟前
青鸾云步:基于 Cordova 的 AI 导盲机器人 APP 全栈开发实战
人工智能·app·导盲·轮足机器人·青鸾云步
深兰科技1 小时前
韩国KAIST AI半导体高管项目代表团到访深兰科技,聚焦AI算力与智能产业合作机会
人工智能·机器人·symfony·ai算力·深兰科技·韩国科学技术院·kaist
快乐on9仔1 小时前
NLP学习(一)transformers之pipeline体验
人工智能·深度学习
冬奇Lab1 小时前
Agent系列(六):记忆管理——让 Agent 记住重要的事
人工智能·agent
冬奇Lab1 小时前
一天一个开源项目(第113篇):notebooklm-py - 把 Google NotebookLM 变成可编程 API,还能接入 Claude Code
人工智能·google·开源
字节跳动开源2 小时前
Viking AI 搜索 CLI 正式发布:会说话,就能做搜索推荐
数据库·人工智能·开源