OpenMMLab AI实战营第三次作业踩坑记录

前言

因为没有申请到北京超算,所以一直使用的是自己电脑显卡进行训练。但是windows系统训练linux系统中的示例代码时会有一些问题出现,在此记录一下。

模型训练

教程代码参考

pytorch环境配置问题

本机安装pytorch环境需要根据本机的cuda版本安装,但是可以安装低于本机cuda版本的pytorch。我在安装cuda11.7对应的pytorch时,不管换源还是直接开加速器下载经常会卡住报错,猜测可能是资源支持问题。使用下面的命令容易卡住无法安装。

conda install pytorch torchvision torchaudio pytorch-cuda=11.7 -c pytorch -c nvidia

使用以下命令安装11.6版本的pytorch可以顺利安装。

# CUDA 11.6
conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 cudatoolkit=11.6 -c pytorch -c conda-forge

模型训练多线程问题

若按照给出的教程代码直接训练,则会出现报错:

RuntimeError: class `IterBasedTrainLoop` in mmengine/runner/loops.py:
        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.

这是因为多线程任务出现报错,windows系统和linux系统对于多线程的支持有所不同。解决问题也比较简单,将模型启动的代码:

# register all modules in mmseg into the registries
# do not init the default scope here because it will be init in the runner
register_all_modules(init_default_scope=False)
runner = Runner.from_cfg(cfg)
runner.train()

改为:

# register all modules in mmseg into the registries
# do not init the default scope here because it will be init in the runner
register_all_modules(init_default_scope=False)
runner = Runner.from_cfg(cfg)
if __name__ == '__main__':
	runner.train()

这样就可以解决多线程报错的问题。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值