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)
相关推荐
胡伯来了3 分钟前
19. Transformers - 文本领域的任务类
人工智能·transformer·多模态·transformers
Fabarta技术团队4 分钟前
枫清科技项目成功入选市科委、中关村管委会2025年重点应用场景项目名单
人工智能·科技
是店小二呀4 分钟前
出差忘带文件?我的急救方案节点小宝4.0
人工智能
李子琪。15 分钟前
AI创新创业:从技术赋能到范式革命
人工智能
LJ979511117 分钟前
智能连接:Infoseek如何重新定义媒体发布效率
大数据·人工智能
字节跳动视频云技术团队18 分钟前
从“抖音同款”到“豆包同款”:视频云正在进入 Agent 时代
人工智能
狮子也疯狂19 分钟前
昇腾ModelSlim工具:大模型量化推理优化实践指南
人工智能
小白开始进步21 分钟前
OpenCV图像滤波:Python实战指南
人工智能·python·opencv
子夜江寒27 分钟前
PyTorch:基于MNIST的手写数字识别
pytorch·python·深度学习
island131427 分钟前
PyTorch 2.0 核心技术深度解析torch.compile 从原理到实践
人工智能·pytorch·python