深度学习pytorch报错集锦

2,852 阅读2分钟
  • 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__、

  • pycharm无法import同一目录文件

       解决:解决链接

  • PIL和opencv的RGB格式也算是两种格式,需要转换
  • linux终端运行报错,段错误有可能是import的时候模块不存在
  • cpu训练模型太慢了,必须使用gpu,安装cuda和gpu驱动,但会遇到pytorch cuda版本和电脑装的gpu驱动版本不一致,一般通过改变pytorch版本来解决问题(重装驱动坑比较多)。尝试过将驱动对应的pytorch版本whl下载本地安装,但是报错与当前平台不兼容(估计是python版本),最后通过百度使用conda安装cuda9.0版本pytorch解决该问题
  • 访问神经网络模型内部的变量,使用model.module.来访问
  • conda安装较慢要进行换源,换成清华源
  • 使用opencv处理pytorch输出的tensor图片组要注意,类型需要转成byte(),范围要乘以255,channel改成最后一个维度,参考此链接,但是发现visdom可视化网页中的图片比链接中方法通过tensor获取到的图片质量更高,具体怎么做到的还没有研究
  •  报错:RuntimeError: running_mean should contain 64 elements not 128

        问题在于Batchnorm时代码写的128维,但是运行时传递的维度是64

  • python报错会具体到源码文件,有时候看一下源码可以立马找到解决方案
  • error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": https://visualstudio.microsoft.com/downloads/

       解决链接