Mercurial Hosting > traffic-intelligence
changeset 893:ff92801e5c54
updated hog to scikit-image 0.13 (needed to add a block_norm attribute in classifier.cfg)
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Tue, 30 May 2017 16:10:18 -0400 |
parents | f766fe0995f4 |
children | 0c1fed9e8862 |
files | classifier.cfg python/cvutils.py python/moving.py python/storage.py scripts/classify-objects.py |
diffstat | 5 files changed, 10 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/classifier.cfg Fri May 05 00:07:33 2017 -0400 +++ b/classifier.cfg Tue May 30 16:10:18 2017 -0400 @@ -14,6 +14,8 @@ hog-npixels-cell = 8 # number of cells per block for HoG computation hog-ncells-block = 2 +# block normalization method (L1, L1-sqrt, L2, L2-Hys) +hog-block-norm = L2-Hys # method to aggregate road user speed speed-aggregation-method = median # number of frames to ignore at both ends of a series (noisy)
--- a/python/cvutils.py Fri May 05 00:07:33 2017 -0400 +++ b/python/cvutils.py Tue May 30 16:10:18 2017 -0400 @@ -605,10 +605,10 @@ from skimage.feature import hog from skimage import color, transform - def HOG(image, rescaleSize = (64, 64), orientations=9, pixelsPerCell=(8, 8), cellsPerBlock=(2, 2), visualize=False, normalize=False): + def HOG(image, rescaleSize = (64, 64), orientations=9, pixelsPerCell=(8,8), cellsPerBlock=(2,2), blockNorm='L1', visualize=False, normalize=False): bwImg = color.rgb2gray(image) inputImg = transform.resize(bwImg, rescaleSize) - features = hog(inputImg, orientations, pixelsPerCell, cellsPerBlock, visualize, normalize) + features = hog(inputImg, orientations, pixelsPerCell, cellsPerBlock, blockNorm, visualize, normalize) if visualize: from matplotlib.pyplot import imshow, figure, subplot hogViz = features[1] @@ -620,11 +620,11 @@ imshow(hogViz) return float32(features) - def createHOGTrainingSet(imageDirectory, classLabel, rescaleSize = (64, 64), orientations=9, pixelsPerCell=(8, 8), cellsPerBlock=(2, 2), visualize=False, normalize=False): + def createHOGTrainingSet(imageDirectory, classLabel, rescaleSize = (64,64), orientations=9, pixelsPerCell=(8,8), blockNorm='L1', cellsPerBlock=(2, 2), visualize=False, normalize=False): inputData = [] for filename in listdir(imageDirectory): img = imread(imageDirectory+filename) - features = HOG(img, rescaleSize, orientations, pixelsPerCell, cellsPerBlock, visualize, normalize) + features = HOG(img, rescaleSize, orientations, pixelsPerCell, cellsPerBlock, blockNorm, visualize, normalize) inputData.append(features) nImages = len(inputData)
--- a/python/moving.py Fri May 05 00:07:33 2017 -0400 +++ b/python/moving.py Tue May 30 16:10:18 2017 -0400 @@ -1577,7 +1577,7 @@ self.userTypes = {} - def classifyUserTypeHoGSVMAtInstant(self, img, instant, homography, width, height, px, py, minNPixels, rescaleSize, orientations, pixelsPerCell, cellsPerBlock): + def classifyUserTypeHoGSVMAtInstant(self, img, instant, homography, width, height, px, py, minNPixels, rescaleSize, orientations, pixelsPerCell, cellsPerBlock, blockNorm): '''Extracts the image box around the object (of square size max(width, height) of the box around the features, with an added px or py for width and height (around the box)) @@ -1585,7 +1585,7 @@ and applies the SVM model on it''' croppedImg, yCropMin, yCropMax, xCropMin, xCropMax = cvutils.imageBox(img, self, instant, homography, width, height, px, py, minNPixels) if croppedImg is not None and len(croppedImg) > 0: - hog = cvutils.HOG(croppedImg, rescaleSize, orientations, pixelsPerCell, cellsPerBlock, visualize=False, normalize=False) + hog = cvutils.HOG(croppedImg, rescaleSize, orientations, pixelsPerCell, cellsPerBlock, blockNorm, visualize=False, normalize=False) self.userTypes[instant] = int(self.appearanceClassifier.predict(hog)) else: self.userTypes[instant] = userType2Num['unknown']
--- a/python/storage.py Fri May 05 00:07:33 2017 -0400 +++ b/python/storage.py Tue May 30 16:10:18 2017 -0400 @@ -1252,6 +1252,7 @@ self.hogNPixelsPerCell = (x, x) x = config.getint(self.sectionHeader, 'hog-ncells-block') self.hogNCellsPerBlock = (x, x) + self.hogBlockNorm = config.get(self.sectionHeader, 'hog-block-norm') self.speedAggregationMethod = config.get(self.sectionHeader, 'speed-aggregation-method') self.nFramesIgnoreAtEnds = config.getint(self.sectionHeader, 'nframes-ignore-at-ends')
--- a/scripts/classify-objects.py Fri May 05 00:07:33 2017 -0400 +++ b/scripts/classify-objects.py Tue May 30 16:10:18 2017 -0400 @@ -117,7 +117,7 @@ obj.classifyUserTypeHoGSVM(minSpeedEquiprobable = classifierParams.minSpeedEquiprobable, speedProbabilities = speedProbabilities) pastObjects.append(obj) else: - obj.classifyUserTypeHoGSVMAtInstant(img, frameNum, invHomography, width, height, classifierParams.percentIncreaseCrop, classifierParams.percentIncreaseCrop, classifierParams.minNPixels, classifierParams.hogRescaleSize, classifierParams.hogNOrientations, classifierParams.hogNPixelsPerCell, classifierParams.hogNCellsPerBlock) + obj.classifyUserTypeHoGSVMAtInstant(img, frameNum, invHomography, width, height, classifierParams.percentIncreaseCrop, classifierParams.percentIncreaseCrop, classifierParams.minNPixels, classifierParams.hogRescaleSize, classifierParams.hogNOrientations, classifierParams.hogNPixelsPerCell, classifierParams.hogNCellsPerBlock, classifierParams.hogBlockNorm) currentObjects.append(obj) else: currentObjects.append(obj)