Mercurial Hosting > traffic-intelligence
diff scripts/learn-motion-patterns.py @ 878:8e8ec4ece66e
minor + bug corrected in motion pattern learning
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Fri, 10 Mar 2017 15:31:26 -0500 |
parents | 1535251a1f40 |
children | 9fd7b18f75b4 |
line wrap: on
line diff
--- a/scripts/learn-motion-patterns.py Wed Mar 08 17:46:28 2017 -0500 +++ b/scripts/learn-motion-patterns.py Fri Mar 10 15:31:26 2017 -0500 @@ -10,7 +10,7 @@ parser = argparse.ArgumentParser(description='The program learns prototypes for the motion patterns') #, epilog = '' #parser.add_argument('--cfg', dest = 'configFilename', help = 'name of the configuration file') parser.add_argument('-d', dest = 'databaseFilename', help = 'name of the Sqlite database file', required = True) -parser.add_argument('-t', dest = 'trajectoryType', help = 'type of trajectories to display', choices = ['objectfeatures', 'feature', 'object'], default = 'objectfeatures') +parser.add_argument('-t', dest = 'trajectoryType', help = 'type of trajectories to learn from', choices = ['objectfeatures', 'feature', 'object'], default = 'objectfeatures') parser.add_argument('--max-nobjectfeatures', dest = 'maxNObjectFeatures', help = 'maximum number of features per object to load', type = int, default = 3) parser.add_argument('-n', dest = 'nTrajectories', help = 'number of the object or feature trajectories to load', type = int, default = None) parser.add_argument('-e', dest = 'epsilon', help = 'distance for the similarity of trajectory points', type = float, required = True) @@ -28,8 +28,10 @@ # TODO add possibility to cluter with velocities trajectoryType = args.trajectoryType +prototypeType = args.trajectoryType if args.trajectoryType == 'objectfeatures': trajectoryType = 'object' + prototypeType = 'feature' #features = storage.loadTrajectoriesFromSqlite(databaseFilename, args.trajectoryType) objects = storage.loadTrajectoriesFromSqlite(args.databaseFilename, trajectoryType, withFeatures = (args.trajectoryType == 'objectfeatures'), objectNumbers = args.nTrajectories, timeStep = args.positionSubsamplingRate) @@ -37,7 +39,7 @@ if args.trajectoryType == 'objectfeatures': features = [] for o in objects: - o.getNLongestFeatures(args.maxNObjectFeatures) + features += o.getNLongestFeatures(args.maxNObjectFeatures) objects = features trajectories = [o.getPositions().asArray().T for o in objects] @@ -52,7 +54,7 @@ clusterSizes = ml.computeClusterSizes(labels, prototypeIndices, -1) print(clusterSizes) -storage.savePrototypesToSqlite(args.databaseFilename, [objects[i].getNum() for i in prototypeIndices], args.trajectoryType, [clusterSizes[i] for i in prototypeIndices]) # if saving filenames, add for example [objects[i].dbFilename for i in prototypeIndices] +storage.savePrototypesToSqlite(args.databaseFilename, [objects[i].getNum() for i in prototypeIndices], prototypeType, [clusterSizes[i] for i in prototypeIndices]) # if saving filenames, add for example [objects[i].dbFilename for i in prototypeIndices] if args.saveSimilarities: np.savetxt(utils.removeExtension(args.databaseFilename)+'-prototype-similarities.txt.gz', similarities, '%.4f')