Mercurial Hosting > traffic-intelligence
changeset 898:1fc901d983ed
better take into account unknown appearance classification
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Wed, 21 Jun 2017 17:21:03 -0400 |
parents | f5a49b603e8b |
children | 1466a63dd1cf |
files | python/moving.py scripts/classify-objects.py |
diffstat | 2 files changed, 13 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/python/moving.py Wed Jun 14 01:11:56 2017 -0400 +++ b/python/moving.py Wed Jun 21 17:21:03 2017 -0400 @@ -1590,7 +1590,7 @@ else: self.userTypes[instant] = userType2Num['unknown'] - def classifyUserTypeHoGSVM(self, pedBikeCarSVM = None, width = 0, height = 0, homography = None, images = None, bikeCarSVM = None, pedBikeSpeedTreshold = float('Inf'), bikeCarSpeedThreshold = float('Inf'), minSpeedEquiprobable = -1, speedProbabilities = None, aggregationFunc = median, nInstantsIgnoredAtEnds = 0, px = 0.2, py = 0.2, minNPixels = 800, rescaleSize = (64, 64), orientations = 9, pixelsPerCell = (8,8), cellsPerBlock = (2,2)): + def classifyUserTypeHoGSVM(self, pedBikeCarSVM = None, width = 0, height = 0, homography = None, images = None, bikeCarSVM = None, pedBikeSpeedTreshold = float('Inf'), bikeCarSpeedThreshold = float('Inf'), minSpeedEquiprobable = -1, speedProbabilities = None, aggregationFunc = median, maxPercentUnknown = 0.5, nInstantsIgnoredAtEnds = 0, px = 0.2, py = 0.2, minNPixels = 800, rescaleSize = (64, 64), orientations = 9, pixelsPerCell = (8,8), cellsPerBlock = (2,2)): '''Agregates SVM detections in each image and returns probability (proportion of instants with classification in each category) @@ -1611,14 +1611,20 @@ userTypeProbabilities = {userType2Num['car']: 1., userType2Num['pedestrian']: 1., userType2Num['bicycle']: 1.} else: userTypeProbabilities = {userType2Num[userTypename]: speedProbabilities[userTypename](self.aggregatedSpeed) for userTypename in speedProbabilities} - # result is P(Class|Appearance) x P(Speed|Class) + # compute P(Class|Appearance) nInstantsUserType = {userTypeNum: 0 for userTypeNum in userTypeProbabilities}# number of instants the object is classified as userTypename + nInstantsUserType[userType2Num['unknown']] = 0 for t in self.userTypes: - nInstantsUserType[self.userTypes[t]] = nInstantsUserType.get(self.userTypes[t], 0) + 1 - for userTypeNum in userTypeProbabilities: - userTypeProbabilities[userTypeNum] *= nInstantsUserType[userTypeNum] + nInstantsUserType[self.userTypes[t]] += 1 #nInstantsUserType.get(self.userTypes[t], 0) + 1 + # result is P(Class|Appearance) x P(Speed|Class) + if nInstantsUserType[userType2Num['unknown']] < maxPercentUnknown*self.length(): # if not too many unknowns + for userTypeNum in userTypeProbabilities: + userTypeProbabilities[userTypeNum] *= nInstantsUserType[userTypeNum] # class is the user type that maximizes usertype probabilities - self.setUserType(utils.argmaxDict(userTypeProbabilities)) + if nInstantsUserType[userType2Num['unknown']] >= maxPercentUnknown*self.length() and (speedProbabilities is None or self.aggregatedSpeed < minSpeedEquiprobable): # if no speed information and too many unknowns + self.setUserType(userType2Num['unknown']) + else: + self.setUserType(utils.argmaxDict(userTypeProbabilities)) def classifyUserTypeArea(self, areas, homography): '''Classifies the object based on its location (projected to image space)
--- a/scripts/classify-objects.py Wed Jun 14 01:11:56 2017 -0400 +++ b/scripts/classify-objects.py Wed Jun 21 17:21:03 2017 -0400 @@ -114,7 +114,7 @@ obj.initClassifyUserTypeHoGSVM(speedAggregationFunc, pedBikeCarSVM, bikeCarSVM, classifierParams.maxPedestrianSpeed, classifierParams.maxCyclistSpeed, classifierParams.nFramesIgnoreAtEnds) currentObjects.append(obj) elif inter.last == frameNum: - obj.classifyUserTypeHoGSVM(minSpeedEquiprobable = classifierParams.minSpeedEquiprobable, speedProbabilities = speedProbabilities) + obj.classifyUserTypeHoGSVM(minSpeedEquiprobable = classifierParams.minSpeedEquiprobable, speedProbabilities = speedProbabilities, maxPercentUnknown = 0.5) # todo add maxPercentUnknown in cfg 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, classifierParams.hogBlockNorm)