# HG changeset patch # User Nicolas Saunier # Date 1529467623 14400 # Node ID 8ffb3ae9f3d24a5ca146660b8d704050514554a8 # Parent d0e339359d8ad505cc14303418299bd52845d571 work in progress diff -r d0e339359d8a -r 8ffb3ae9f3d2 scripts/learn-motion-patterns.py --- a/scripts/learn-motion-patterns.py Tue Jun 19 17:07:50 2018 -0400 +++ b/scripts/learn-motion-patterns.py Wed Jun 20 00:07:03 2018 -0400 @@ -25,7 +25,7 @@ parser.add_argument('--display', dest = 'display', help = 'display trajectories', action = 'store_true') parser.add_argument('--save-similarities', dest = 'saveSimilarities', help = 'save computed similarities (in addition to prototypes)', action = 'store_true') parser.add_argument('--save-matches', dest = 'saveMatches', help = 'saves the assignments of the objects (not for features) to the prototypes', action = 'store_true') -parser.add_argument('--assign', dest = 'assign', help = 'assigns the objects to the prototypes and saves them (do not use min cluster size as it will discard prototypes at the beginning if the initial cluster is too small)', action = 'store_true') +parser.add_argument('--assign', dest = 'assign', help = 'assigns the objects to the prototypes and saves the assignments', action = 'store_true') args = parser.parse_args() @@ -78,26 +78,27 @@ else: prototypeIndices = initialPrototypeIndices -if args.assign: - if not args.learn and args.minClusterSize >= 1: - print('Warning: you did not learn the prototypes and you are using minimum cluster size of {}, which may lead to removing prototypes and assigning them to others'.format(args.minClusterSize)) - prototypeIndices, labels = ml.assignToPrototypeClusters(trajectories, prototypeIndices, similarities, args.minSimilarity, similarityFunc, args.minClusterSize) +if args.assign: # TODO don't touch initial prototypes if not from same db as trajectories + #if not args.learn and args.minClusterSize >= 1: # allow only + # print('Warning: you did not learn the prototypes and you are using minimum cluster size of {}, which may lead to removing prototypes and assigning them to others'.format(args.minClusterSize)) + # if args.minClusterSize >= 1: + # if initialPrototypeIndices is None: + # prototypeIndices, labels = ml.assignToPrototypeClusters(trajectories, prototypeIndices, similarities, args.minSimilarity, similarityFunc, args.minClusterSize) + # else: + # print('Not assigning with non-zero minimum cluster size and initial prototypes (would remove initial prototypes based on other trajectories') + # else: + # prototypeIndices, labels = ml.assignToPrototypeClusters(trajectories, prototypeIndices, similarities, args.minSimilarity, similarityFunc) + prototypeIndices, labels = ml.assignToPrototypeClusters(trajectories, prototypeIndices, similarities, args.minSimilarity, similarityFunc) clusterSizes = ml.computeClusterSizes(labels, prototypeIndices, -1) print(clusterSizes) -if args.learn or args.assign: +if args.learn and not args.assign: prototypes = [] for i in prototypeIndices: - if args.assign: - nMatchings = clusterSizes[i]-1 - #else: - # nMatchings = 0 if i