Mercurial Hosting > traffic-intelligence
comparison scripts/learn-motion-patterns.py @ 920:499154254f37
improved prototype loading
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Wed, 05 Jul 2017 16:30:04 -0400 |
parents | 7b3f2e0a2652 |
children | 630934595871 |
comparison
equal
deleted
inserted
replaced
919:7b3f2e0a2652 | 920:499154254f37 |
---|---|
8 import ml, utils, storage | 8 import ml, utils, storage |
9 | 9 |
10 parser = argparse.ArgumentParser(description='The program learns prototypes for the motion patterns') #, epilog = '' | 10 parser = argparse.ArgumentParser(description='The program learns prototypes for the motion patterns') #, epilog = '' |
11 #parser.add_argument('--cfg', dest = 'configFilename', help = 'name of the configuration file') | 11 #parser.add_argument('--cfg', dest = 'configFilename', help = 'name of the configuration file') |
12 parser.add_argument('-d', dest = 'databaseFilename', help = 'name of the Sqlite database file', required = True) | 12 parser.add_argument('-d', dest = 'databaseFilename', help = 'name of the Sqlite database file', required = True) |
13 parser.add_argument('-r', dest = 'initialPrototypeDatabaseFilename', help = 'name of the Sqlite database file for prototypes to start the algorithm with') | |
13 parser.add_argument('-t', dest = 'trajectoryType', help = 'type of trajectories to learn from', choices = ['objectfeatures', 'feature', 'object'], default = 'objectfeatures') | 14 parser.add_argument('-t', dest = 'trajectoryType', help = 'type of trajectories to learn from', choices = ['objectfeatures', 'feature', 'object'], default = 'objectfeatures') |
14 parser.add_argument('--max-nobjectfeatures', dest = 'maxNObjectFeatures', help = 'maximum number of features per object to load', type = int, default = 3) | 15 parser.add_argument('--max-nobjectfeatures', dest = 'maxNObjectFeatures', help = 'maximum number of features per object to load', type = int, default = 1) |
15 parser.add_argument('-n', dest = 'nTrajectories', help = 'number of the object or feature trajectories to load', type = int, default = None) | 16 parser.add_argument('-n', dest = 'nTrajectories', help = 'number of the object or feature trajectories to load', type = int, default = None) |
16 parser.add_argument('-e', dest = 'epsilon', help = 'distance for the similarity of trajectory points', type = float, required = True) | 17 parser.add_argument('-e', dest = 'epsilon', help = 'distance for the similarity of trajectory points', type = float, required = True) |
17 parser.add_argument('--metric', dest = 'metric', help = 'metric for the similarity of trajectory points', default = 'cityblock') # default is manhattan distance | 18 parser.add_argument('--metric', dest = 'metric', help = 'metric for the similarity of trajectory points', default = 'cityblock') # default is manhattan distance |
18 parser.add_argument('-s', dest = 'minSimilarity', help = 'minimum similarity to put a trajectory in a cluster', type = float, required = True) | 19 parser.add_argument('-s', dest = 'minSimilarity', help = 'minimum similarity to put a trajectory in a cluster', type = float, required = True) |
19 parser.add_argument('-c', dest = 'minClusterSize', help = 'minimum cluster size', type = int, default = None) | 20 parser.add_argument('-c', dest = 'minClusterSize', help = 'minimum cluster size', type = int, default = None) |
28 | 29 |
29 # use cases | 30 # use cases |
30 # 1. learn proto from one file, save in same or another (with traj) | 31 # 1. learn proto from one file, save in same or another (with traj) |
31 # 2. load proto, load objects, update proto, save proto | 32 # 2. load proto, load objects, update proto, save proto |
32 # 3. assign objects from one db to proto | 33 # 3. assign objects from one db to proto |
33 # 4. load objects from several files, save in another | 34 # 4. load objects from several files, save in another -> see metadata: site with view and times |
34 # 5. keep prototypes, with positions/velocities, in separate db (keep link to original data through filename, type and index) | 35 # 5. keep prototypes, with positions/velocities, in separate db (keep link to original data through filename, type and index) |
35 | 36 |
36 # TODO add possibility to cluter with velocities | 37 # TODO add possibility to cluter with velocities |
37 # TODO add possibility to start with saved prototypes so that one can incrementally learn from several databases | 38 # TODO add possibility to start with saved prototypes so that one can incrementally learn from several databases |
38 # save prototypes with database name, add option to keep trajectory along: if saved in same db, no need | |
39 # load proto must load the movingobject | |
40 # save the objects that match the prototypes | 39 # save the objects that match the prototypes |
41 # write an assignment function for objects | 40 # write an assignment function for objects |
42 | 41 |
43 trajectoryType = args.trajectoryType | 42 trajectoryType = args.trajectoryType |
44 prototypeType = args.trajectoryType | 43 prototypeType = args.trajectoryType |
66 | 65 |
67 clusterSizes = ml.computeClusterSizes(labels, prototypeIndices, -1) | 66 clusterSizes = ml.computeClusterSizes(labels, prototypeIndices, -1) |
68 print(clusterSizes) | 67 print(clusterSizes) |
69 | 68 |
70 prototypes = [objects[i] for i in prototypeIndices] | 69 prototypes = [objects[i] for i in prototypeIndices] |
71 storage.savePrototypesToSqlite(args.databaseFilename, [p.getNum() for p in prototypes], prototypeType, prototypes, [clusterSizes[i] for i in prototypeIndices]) # if saving filenames, add for example [objects[i].dbFilename for i in prototypeIndices] | 70 storage.savePrototypesToSqlite(args.databaseFilename, [p.getNum() for p in prototypes], prototypeType, [clusterSizes[i] for i in prototypeIndices]) # if saving filenames, add for example [objects[i].dbFilename for i in prototypeIndices] |
72 | 71 |
73 if args.saveSimilarities: | 72 if args.saveSimilarities: |
74 np.savetxt(utils.removeExtension(args.databaseFilename)+'-prototype-similarities.txt.gz', similarities, '%.4f') | 73 np.savetxt(utils.removeExtension(args.databaseFilename)+'-prototype-similarities.txt.gz', similarities, '%.4f') |
75 | 74 |
76 # if args.saveMatches: | 75 # if args.saveMatches: |