SSD训练自己的数据集pytorch实现!!踩坑实录

SSD训练自己的数据集pytorch实现!!踩坑实录

大部分人都是按照这个github上的pytorch实例进行的,毕竟是3年前的东西,bug不是一般的多啊!!!
大神的github 链接: link.

我先开始用tensorflow和keras 没一个能实现的 代码都血坑无比

caffe实现的多 但是我在windows上 实现,没办法装caffe 佛了

有ubuntu的童鞋还是考虑caffe去源码实现把

我的配置

1060显卡 阉割版5GB
pytorch 1.01 虽然0.41最好用
可能会出现一些warning 但是完全没有关系
CUDA 9.0

安装pytorch

按照github上的pytorch handbook按照教程下载把
链接: link.
https://github.com/zergtant/pytorch-handbook

// A code block
pytorch handbook

SSD训练自己的数据集pytorch实现!!踩坑实录_第1张图片

一些大神的塘坑血泪史,https://blog.csdn.net/dingkm666/article/details/88775428
https://blog.csdn.net/lxy_2011/article/details/99680399

还有要下这个预训练模型,github上给的网址下不了,去CSDN上花钱买把 ,淘宝几毛钱,
在这里插入图片描述

踩坑第一步

SSD训练自己的数据集pytorch实现!!踩坑实录_第2张图片SSD训练自己的数据集pytorch实现!!踩坑实录_第3张图片
数据集我是用的VOC ,记得要准备VOC2007和VOC2012两份
完全一样没关系 一定要准备 不然报错 还有就是COCO数据集 准备方式一样哈。

踩坑第二步

数据集生成的XML文件一定不要有中文,连路径也不能有,txt文件也是一样,,不然会有gbk错误!!!!
SSD训练自己的数据集pytorch实现!!踩坑实录_第4张图片
voc0712这个一定要好好改 改
SSD训练自己的数据集pytorch实现!!踩坑实录_第5张图片
像下面这样的源代码是不行的,只有一类,,的话按照上面的改哈。
一定注意括号 [ ( ’ 类别 ’ ) ]

// An highlighted block
VOC_CLASSES=('dog')

不然会出现keyerror 一堆 然后dog 的首字母 小写!!!!!!!!!
Dog也会报错!!!!!!!!!!!!!!

踩坑第三步

所有的classes都要改 就算是VOC数据集 你的config文件里的 COCO数据集的classes也要改

不然又报错 坑的一批SSD训练自己的数据集pytorch实现!!踩坑实录_第6张图片
记住是所有有classes的地方,包括train.py test.py 所有都必须一样

记住先改classes再训练,不然训练的参数会出现错误

什么参数不匹配 坑死
RuntimeError: Error(s) in loading state_dict for SSD: size mismatch for conf.0.weight: copying a param with shape torch.Size([8, 512, 3, 3]) from checkpoint, the shape in current model is torch.Size([84, 512, 3, 3]). size mismatch for conf.0.bias: copying a param with shape torch.Size([8]) from checkpoint, the shape in current model is torch.Size([84]). size mismatch for conf.1.weight: copying a param with shape torch.Size([12, 1024, 3, 3]) from checkpoint, the shape in current model is torch.Size([126, 1024, 3, 3]). size mismatch for conf.1.bias: copying a param with shape torch.Size([12]) from checkpoint, the shape in current model is torch.Size([126]). size mismatch for conf.2.weight: copying a param with shape torch.Size([12, 512, 3, 3]) from checkpoint, the shape in current model is torch.Size([126, 512, 3, 3]). size mismatch for conf.2.bias: copying a param with shape torch.Size([12]) from checkpoint, the shape in current model is torch.Size([126]).

踩坑第四步

按顺序先运行

// An highlighted block
python eval.py
python test.py
#进到 demo里  打开jupyter

然后可以用demo.ipynb
可以进行可视化看看自己的检测结果

这是eval.py生成的 不知道啥用
在这里插入图片描述
这是test.py生成的 ,帮你看看自己的测试集里的预测框坐标和类别

SSD训练自己的数据集pytorch实现!!踩坑实录_第7张图片
最后放张大狗子
SSD训练自己的数据集pytorch实现!!踩坑实录_第8张图片
还有什么问题可以给我留言哈哈

你可能感兴趣的:(pytorch,ssd,bug,keras,python)