Python implements HOG+SVM classification of CIFAR-10 datasets (top)

Source: Internet
Author: User
Tags svm

This blog is only used for learning, if there are errors in the place, please correct me, if you need to reprint to indicate the source.

See machine learning also has a period of time, these two days finally bravely stepped out the first step, realized the HOG+SVM on the picture classification, the specific code can be downloaded on GitHub, Https://github.com/subicWang/HOG-SVM-classifer. Everyone says HOG+SVM is a very well-aligned pair in pedestrian detection. As for why, I can not speak clearly. I guess this is a good pair of applications in the picture classification effect should also be nice, it turns out that really OK, the speed is very fast, the classification of the correct rate is OK. The dataset I'm using is http://www.cs.toronto.edu/~kriz/cifar.html. Picture features hog extraction process, this article does not explain, a lot of blog is certainly more than I speak clearly. Then I will directly stick out my code, convenient for people to refer to.

def gethogfeat (image,stride = 8, orientations=8, pixels_per_cell= (8, 8), cells_per_block= (2, 2)): CX, cy = Pixels_per_c Ell bx, by = Cells_per_block sx, sy = image.shape n_cellsx = Int. (Np.floor (SX/CX)) # Number of cells in x N _cellsy = Int (Np.floor (sy/CY)) # Number of cells in y N_blocksx = (N_CELLSX-BX) + 1 N_blocksy = (n_cellsy-by  ) + 1 GX = zeros (SX, SY), dtype=np.double) Gy = zeros (SX, SY), dtype=np.double) EPS = 1e-5 grad = zeros (SX, Sy, 2), dtype=np.double) for I in xrange (1, sx-1): for J in Xrange (1, sy-1): Gx[i, j] = Image[i, j-1 ]-Image[i, j+1] gy[i, j] = Image[i+1, j]-Image[i-1, J] Grad[i, j, 0] = arctan (Gy[i, J]/(Gx[i, J] + EPS)) * 180/math.pi if Gx[i, J] < 0:grad[i, J, 0] + + grad[i, j, 0] = ( Grad[i, J, 0] +)% Grad[i, j, 1] = sqrt (gy[i, j] * * 2 + gx[i, j] * * 2) Normalised_blocks = Np.zeros ( (N_blocksy, N_BLOCKSX, bY * bx * orientations))) for Y in Xrange (N_blocksy): For x in Xrange (N_BLOCKSX): block = Grad[y*stride  : y*stride+16, x*stride:x*stride+16] Hist_block = zeros (+, dtype=double) EPS = 1e-5 for k                    In Xrange (by): for M in Xrange (BX): cell = block[k*8: (k+1) *8, m*8: (m+1) *8] Hist_cell = Zeros (8, dtype=double) for I in Xrange (CY): for J in Xrange (c                    X): n = Int (cell[i, j, 0]/a) hist_cell[n] + = Cell[i, J, 1] hist_block[(k * bx + M) * Orientations: (k * bx + M + 1) * orientations] = hist_cell[:] Normalised_ Blocks[y, x,:] = Hist_block/np.sqrt (Hist_block.sum () * * 2 + EPS) return Normalised_blocks.ravel ()

Familiar with the Hog feature extraction process should be able to understand, I will not comment. The simple implementation of this certainly does not meet my requirements, I have been unable to understand why the gradient of the pixel points in these feature extraction algorithms is determined only by the horizontal and vertical pixels, the other points around the point does not work? I did some experiments on this and I share it in the next article.

Python implements HOG+SVM classification of CIFAR-10 datasets (top)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.