在训练YOLOv3的时候用了4个类别,car,bus,truck和tricycle,训练了2w轮,loss不到0.2
但是在训练集和测试集分别测试mAP的时候缺出现了很大的差距。
val result:
class name: bus
('ap', 0.22807790544644976)
class name: car
('ap', 0.63199984246435803)
class name: tricycle
('ap', 0.34770907068496959)
class name: truck
('ap', 0.078184331844917104)
map: 0.32149278761
train result:
class name: bus
('ap', 0.6353776117514065)
class name: car
('ap', 0.79207402671428995)
class name: tricycle
('ap', 0.79698736110859469)
class name: truck
('ap', 0.42166913757946789)
map: 0.661527034288
分析原因(能想到的原因,不一定全都正确):
bus : 579
tricycle : 3713
truck : 680
car : 24772
======================
Total numbers: 29744
可以看出bus和truck的确太少了,于是写了个脚本提取所有训练集里面带bus,truck和tricycle的样本,重新训练。
bus : 1639
tricycle : 13493
truck : 2721
car : 43359
======================
Total numbers: 61212
#decay=0.0005
decay=0.005
angle=0 # 通过旋转角度来生成更多训练样本
saturation = 1.5 # 通过调整饱和度来生成更多训练样本
exposure = 1.5 # 通过调整曝光量来生成更多训练样本
hue=.1 # 通过调整色调来生成更多训练样本
增加噪声也是深度学习中的一种避免过拟合的方法(没办法,深度学习模型太复杂,容易过拟合),添加噪声的途径有很多,可以在输入数据上添加,增大数据的多样性,可以在权值上添加噪声,这种方法类似于L2正则化。
6. 增大batchsize
硬件限制,1080ti最大的batchsize只能是4
batch=128
subdivisions=32
7. 数据不均衡,car的数量太多而bus和truck太少。虽然说YOLOv3论文中说这不是个问题,但是可以考虑尝试RefineNet来训练试试会不会好一点。
1.1w张样本迭代1.5w次的结果暂时如下,效果依旧不是很好,loss在0.5左右,还在继续尝试。
val result:
class name: bus
('ap', 0.49744826031193373)
class name: car
('ap', 0.75586805455467787)
class name: tricycle
('ap', 0.50247663224440964)
class name: truck
('ap', 0.3083948817946901)
map: 0.516046957226
train result:
class name: bus
('ap', 0.7455309150992715)
class name: car
('ap', 0.90665062022019083)
class name: tricycle
('ap', 0.84645985229305754)
class name: truck
('ap', 0.73641891265438542)
map: 0.808765075067
奇怪的是之前在18个类别上面的训练却不会出现过拟合。这是在3w张图片中迭代7w次的结果:
val result:
class name: bus
('ap', 0.52726649332001263)
class name: car
('ap', 0.76000162065648669)
class name: tricycle
('ap', 0.53974133766752908)
class name: truck
('ap', 0.36354866982890083)
class name: ad
('ap', 0.43787629619368407)
class name: chair
('ap', 0.39450779507368317)
class name: didi
('ap', 0.0)
class name: group
('ap', 0.38137401095031354)
class name: hello
('ap', 0.064153829510902413)
class name: mobike
('ap', 0.57819527747597532)
class name: motorbike
('ap', 0.57559562246738116)
class name: ofo
('ap', 0.68832771884705535)
class name: other
('ap', 0.34353788302009808)
class name: outdoor
('ap', 0.14473446495671852)
class name: rider
('ap', 0.59438630516472879)
class name: shed
('ap', 0.55684054986302134)
class name: stall
('ap', 0.37180247917258502)
class name: table
('ap', 0.4240612667170468)
map: 0.430330645605
train result:
class name: bus
('ap', 0.53173837303772009)
class name: car
('ap', 0.7580570065705885)
class name: tricycle
('ap', 0.52056363546785689)
class name: truck
('ap', 0.32530568570587204)
class name: ad
('ap', 0.43648750933116109)
class name: chair
('ap', 0.3858413917929846)
class name: didi
('ap', 0.0)
class name: group
('ap', 0.39637954363721961)
class name: hello
('ap', 0.048862940567670307)
class name: mobike
('ap', 0.57263494150864003)
class name: motorbike
('ap', 0.57673691308128028)
class name: ofo
('ap', 0.67930824884318231)
class name: other
('ap', 0.32734148919170775)
class name: outdoor
('ap', 0.1398806741107132)
class name: rider
('ap', 0.58668610550391875)
class name: shed
('ap', 0.536793581534319)
class name: stall
('ap', 0.40860177034251333)
class name: table
('ap', 0.37539503586561956)
map: 0.422589713672