Mercurial Hosting > traffic-intelligence
changeset 914:f228fd649644
corrected bugs in learn-pois.py
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Wed, 28 Jun 2017 23:43:52 -0400 |
parents | 1cd878812529 |
children | 13434f5017dd |
files | python/ml.py scripts/learn-poi.py |
diffstat | 2 files changed, 9 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/python/ml.py Wed Jun 28 17:57:06 2017 -0400 +++ b/python/ml.py Wed Jun 28 23:43:52 2017 -0400 @@ -274,7 +274,7 @@ tmpDataset = dataset/nUnitsPerPixel for i in xrange(model.n_components): mean = model.means_[i]/nUnitsPerPixel - covariance = model.covars_[i]/nUnitsPerPixel + covariance = model.covariances_[i]/nUnitsPerPixel if dataset is not None: plt.scatter(tmpDataset[labels == i, 0], tmpDataset[labels == i, 1], .8, color=colors[i]) plt.annotate(str(i), xy=(mean[0]+1, mean[1]+1))
--- a/scripts/learn-poi.py Wed Jun 28 17:57:06 2017 -0400 +++ b/scripts/learn-poi.py Wed Jun 28 23:43:52 2017 -0400 @@ -8,20 +8,21 @@ import storage, ml -parser = argparse.ArgumentParser(description='The program learns and displays Gaussians fit to beginnings and ends of object trajectories (based on Mohamed Gomaa Mohamed 2015 PhD). TODO: save the data') +parser = argparse.ArgumentParser(description='The program learns and displays Gaussians fit to beginnings and ends of object trajectories (based on Mohamed Gomaa Mohamed 2015 PhD).') 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 = ['feature', 'object'], default = 'object') +parser.add_argument('-n', dest = 'nObjects', help = 'number of objects to display', type = int) parser.add_argument('-norigins', dest = 'nOriginClusters', help = 'number of clusters for trajectory origins', required = True, type = int) parser.add_argument('-ndestinations', dest = 'nDestinationClusters', help = 'number of clusters for trajectory destinations (=norigins if not provided)', type = int) parser.add_argument('--covariance-type', dest = 'covarianceType', help = 'type of covariance of Gaussian model', default = "full") parser.add_argument('-w', dest = 'worldImageFilename', help = 'filename of the world image') parser.add_argument('-u', dest = 'unitsPerPixel', help = 'number of units of distance per pixel', type = float, default = 1.) parser.add_argument('--display', dest = 'display', help = 'display points of interests', action = 'store_true') # default is manhattan distance -parser.add_argument('--assign', dest = 'display', help = 'display points of interests', action = 'store_true') # default is manhattan distance +parser.add_argument('--assign', dest = 'assign', help = 'display points of interests', action = 'store_true') args = parser.parse_args() -objects = storage.loadTrajectoriesFromSqlite(args.databaseFilename, args.trajectoryType) +objects = storage.loadTrajectoriesFromSqlite(args.databaseFilename, args.trajectoryType, args.nObjects) beginnings = [] ends = [] @@ -45,14 +46,15 @@ model=gmm.fit(points) if not model.converged_: print('Warning: model for '+gmmType+' points did not converge') + if args.display or args.assign: + labels = model.predict(points) # plot if args.display: fig = plt.figure() if args.worldImageFilename is not None and args.unitsPerPixel is not None: img = plt.imread(args.worldImageFilename) plt.imshow(img) - labels = model.predict(points) - labels = ml.plotGMMClusters(model, labels, points, fig, nUnitsPerPixel = args.unitsPerPixel) + ml.plotGMMClusters(model, labels, points, fig, nUnitsPerPixel = args.unitsPerPixel) plt.axis('image') plt.title(gmmType) print(gmmType+' Clusters:\n{}'.format(ml.computeClusterSizes(labels, range(model.n_components)))) @@ -60,7 +62,7 @@ storage.savePOIs(args.databaseFilename, model, gmmType, gmmId) # save assignments if args.assign: - pass + pass # savePOIAssignments( gmmId += 1 if args.display: