Advertisement

[自动驾驶]CarND-Vehicle-Detection

阅读量:

听到Vehicle-Detection,我还以为是YOLO,SSD啥的,结果课程里用的是传统的HOG。Excuse me?就是各种论文里被用来踩一脚的SIFT、HOG?那也好吧,深刻体会体会传统方法有多弱鸡。

HOG

HOG之前简单了解过,不要既然要动手干活,还是得了解一些具体的计算细节。http://www.learnopencv.com/histogram-of-oriented-gradients/这篇文章讲得挺好的。

简单来看,HOG提取到的特征有点像低清版图像边缘,有一定鲁棒性,能容忍物体一些轻微光影变换和平移吧。但是特征降维得有点厉害,跟DL提取的特征没法比。不过如果精度要求不高,又想节约计算资源,HOG还是可以用用。

特征提取

用惯了opencv,一开始就查的opencv的api。

这里有tutorial,照猫画虎调用就行 http://www.learnopencv.com/handwritten-digits-classification-an-opencv-c-python-tutorial/ opencv得升级到3.*,科学上网的原因,因为破环境搞半了天。

不过里面说是opensv的svm有bug啥的,而且我更喜欢用sklearn,所以还是用opencv提特征,用sklearn来learn,术业有专攻。

后来仔细看了课程要求才发现提示可以用skimage,感觉封装得比较方便。

hog模版+svc模版,基本长这样:

复制代码
    import  glob
    
    img_positive=[ cv2.cvtColor(cv2.imread(f), cv2.COLOR_BGR2YCrCb) for f in glob.glob("./data/vehicles/*/*.png")]
    img_negative=[ cv2.cvtColor( cv2.imread(f), cv2.COLOR_BGR2YCrCb) for f in glob.glob("./data/non-vehicles/*/*.png")]
    winSize = (64,64)
    blockSize = (16,16)
    blockStride = (8,8)
    cellSize = (8,8)
    nbins = 9
    derivAperture = 1
    winSigma = -1.
    histogramNormType = 0
    L2HysThreshold = 0.2
    gammaCorrection = 1
    nlevels = 64
    useSignedGradients = True
    
    hog = cv2.HOGDescriptor(winSize,blockSize,blockStride,cellSize,nbins,derivAperture,winSigma,histogramNormType,L2HysThreshold,gammaCorrection,nlevels, useSignedGradients)
    
    feature_positive=np.array([(hog.compute(img[:, :, 0]) - 0.14275211)/0.085549206 for img in img_positive])
    feature_negative=np.array([ (hog.compute(img[:, :, 0])- 0.14275211)/0.085549206 for img in img_negative])
    
    SAMPLE_NUM=2000
    small_feature_positive=feature_positive[:SAMPLE_NUM]
    small_feature_negative=feature_negative[:SAMPLE_NUM]
    small_X=np.concatenate((small_feature_positive, small_feature_negative), axis=0)
    # remove last 1L dimension (1000L, 1764L, 1L)
    small_X = small_X.squeeze()
    small_y=np.ones((SAMPLE_NUM*2))
    small_y[SAMPLE_NUM:]=0
    #svc
    
    parameters = {'nu': (0.05, ) , 'gamma':[6e-4, ]}
    
    svc_clf=NuSVC(nu=0.1, kernel='rbf', verbose=True )
    gs_clf =  GridSearchCV(svc_clf, parameters, n_jobs=1, verbose=True )
    
    gs_clf.fit( small_X, small_y)
    
    
    for params, mean_score, scores in gs_clf.grid_scores_:
    print("%0.3f (+/-%0.03f) for %r"  % (mean_score, scores.std() * 2, params))

提示了YCrCb颜色空间效果可能比较好,而且可以增加一些直方图统计类特征。哎,这就是hand-craft特征蛋疼的地方。

表格来源自某大牛的博客。我就懒得去弄了。
我们可以仔细想想,颜色空间转换,直方图统计特征这些东西神经网络能学到么?of course,妥妥的可以。所以我也懒得去弄这玩意了。
Sliding Window Search也是很蛋疼,这样一张图片得计算大半天啊。

随便找了张图,可以识别。


把我的头像误识别为车辆,有两个车灯啥的,确实很像啊~~

总结

传统方法果然很蛋疼。上班没时间调,先随便弄弄吧,后面尝试DL的方法。

全部评论 (0)

还没有任何评论哟~