Mercurial Hosting > traffic-intelligence
comparison python/moving.py @ 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 | ff92801e5c54 |
children | 8f60ecfc2f06 |
comparison
equal
deleted
inserted
replaced
897:f5a49b603e8b | 898:1fc901d983ed |
---|---|
1588 hog = cvutils.HOG(croppedImg, rescaleSize, orientations, pixelsPerCell, cellsPerBlock, blockNorm, visualize=False, normalize=False) | 1588 hog = cvutils.HOG(croppedImg, rescaleSize, orientations, pixelsPerCell, cellsPerBlock, blockNorm, visualize=False, normalize=False) |
1589 self.userTypes[instant] = int(self.appearanceClassifier.predict(hog)) | 1589 self.userTypes[instant] = int(self.appearanceClassifier.predict(hog)) |
1590 else: | 1590 else: |
1591 self.userTypes[instant] = userType2Num['unknown'] | 1591 self.userTypes[instant] = userType2Num['unknown'] |
1592 | 1592 |
1593 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)): | 1593 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)): |
1594 '''Agregates SVM detections in each image and returns probability | 1594 '''Agregates SVM detections in each image and returns probability |
1595 (proportion of instants with classification in each category) | 1595 (proportion of instants with classification in each category) |
1596 | 1596 |
1597 images is a dictionary of images indexed by instant | 1597 images is a dictionary of images indexed by instant |
1598 With default parameters, the general (ped-bike-car) classifier will be used | 1598 With default parameters, the general (ped-bike-car) classifier will be used |
1609 # compute P(Speed|Class) | 1609 # compute P(Speed|Class) |
1610 if speedProbabilities is None or self.aggregatedSpeed < minSpeedEquiprobable: # equiprobable information from speed | 1610 if speedProbabilities is None or self.aggregatedSpeed < minSpeedEquiprobable: # equiprobable information from speed |
1611 userTypeProbabilities = {userType2Num['car']: 1., userType2Num['pedestrian']: 1., userType2Num['bicycle']: 1.} | 1611 userTypeProbabilities = {userType2Num['car']: 1., userType2Num['pedestrian']: 1., userType2Num['bicycle']: 1.} |
1612 else: | 1612 else: |
1613 userTypeProbabilities = {userType2Num[userTypename]: speedProbabilities[userTypename](self.aggregatedSpeed) for userTypename in speedProbabilities} | 1613 userTypeProbabilities = {userType2Num[userTypename]: speedProbabilities[userTypename](self.aggregatedSpeed) for userTypename in speedProbabilities} |
1614 # compute P(Class|Appearance) | |
1615 nInstantsUserType = {userTypeNum: 0 for userTypeNum in userTypeProbabilities}# number of instants the object is classified as userTypename | |
1616 nInstantsUserType[userType2Num['unknown']] = 0 | |
1617 for t in self.userTypes: | |
1618 nInstantsUserType[self.userTypes[t]] += 1 #nInstantsUserType.get(self.userTypes[t], 0) + 1 | |
1614 # result is P(Class|Appearance) x P(Speed|Class) | 1619 # result is P(Class|Appearance) x P(Speed|Class) |
1615 nInstantsUserType = {userTypeNum: 0 for userTypeNum in userTypeProbabilities}# number of instants the object is classified as userTypename | 1620 if nInstantsUserType[userType2Num['unknown']] < maxPercentUnknown*self.length(): # if not too many unknowns |
1616 for t in self.userTypes: | 1621 for userTypeNum in userTypeProbabilities: |
1617 nInstantsUserType[self.userTypes[t]] = nInstantsUserType.get(self.userTypes[t], 0) + 1 | 1622 userTypeProbabilities[userTypeNum] *= nInstantsUserType[userTypeNum] |
1618 for userTypeNum in userTypeProbabilities: | |
1619 userTypeProbabilities[userTypeNum] *= nInstantsUserType[userTypeNum] | |
1620 # class is the user type that maximizes usertype probabilities | 1623 # class is the user type that maximizes usertype probabilities |
1621 self.setUserType(utils.argmaxDict(userTypeProbabilities)) | 1624 if nInstantsUserType[userType2Num['unknown']] >= maxPercentUnknown*self.length() and (speedProbabilities is None or self.aggregatedSpeed < minSpeedEquiprobable): # if no speed information and too many unknowns |
1625 self.setUserType(userType2Num['unknown']) | |
1626 else: | |
1627 self.setUserType(utils.argmaxDict(userTypeProbabilities)) | |
1622 | 1628 |
1623 def classifyUserTypeArea(self, areas, homography): | 1629 def classifyUserTypeArea(self, areas, homography): |
1624 '''Classifies the object based on its location (projected to image space) | 1630 '''Classifies the object based on its location (projected to image space) |
1625 areas is a dictionary of matrix of the size of the image space | 1631 areas is a dictionary of matrix of the size of the image space |
1626 for different road users possible locations, indexed by road user type names | 1632 for different road users possible locations, indexed by road user type names |