Mercurial > hg > nsaunier > traffic-intelligence
comparison scripts/process.py @ 984:a69695d14e59
work on script for large datasets
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Tue, 06 Mar 2018 08:26:13 -0500 |
| parents | 7463c9bc846b |
| children | 668a85c963c3 |
comparison
equal
deleted
inserted
replaced
| 983:7463c9bc846b | 984:a69695d14e59 |
|---|---|
| 1 #! /usr/bin/env python | 1 #! /usr/bin/env python |
| 2 | 2 |
| 3 import sys, argparse | 3 import sys, argparse |
| 4 from pathlib2 import Path | |
| 4 | 5 |
| 5 import storage, cvutils, utils | 6 import storage, events, prediction |
| 6 from metadata import * | 7 from metadata import * |
| 7 | 8 |
| 8 parser = argparse.ArgumentParser(description='This program manages the processing of several files based on a description of the sites and video data in an SQLite database following the metadata module.') | 9 parser = argparse.ArgumentParser(description='This program manages the processing of several files based on a description of the sites and video data in an SQLite database following the metadata module.') |
| 9 parser.add_argument('--db', dest = 'metadataFilename', help = 'name of the metadata file', required = True) | 10 parser.add_argument('--db', dest = 'metadataFilename', help = 'name of the metadata file', required = True) |
| 11 parser.add_argument('--videos', dest = 'videoIds', help = 'indices of the video sequences', nargs = '*', type = int) | |
| 12 parser.add_argument('--pet', dest = 'computePET', help = 'computes PET', action = 'store_true') | |
| 10 | 13 |
| 11 # need way of selecting sites as similar as possible to sql alchemy syntax | 14 # need way of selecting sites as similar as possible to sql alchemy syntax |
| 12 # override tracking.cfg from db | 15 # override tracking.cfg from db |
| 13 # manage cfg files, overwrite them (or a subset of parameters) | 16 # manage cfg files, overwrite them (or a subset of parameters) |
| 14 # delete sqlite files | 17 # delete sqlite files |
| 15 # nprocesses | 18 |
| 19 parser.add_argument('--nthreads', dest = 'nProcesses', help = 'number of processes to run in parallel', type = int, default = 1) | |
| 16 | 20 |
| 17 args = parser.parse_args() | 21 args = parser.parse_args() |
| 22 # files are relative to metadata location | |
| 23 | |
| 24 session = createDatabase(args.metadataFilename) | |
| 25 parentDir = Path(args.metadataFilename).parent | |
| 26 | |
| 27 # todo change prediction parameters | |
| 28 predictionParameters = prediction.CVExactPredictionParameters() | |
| 29 | |
| 30 for videoId in args.videoIds: | |
| 31 vs = session.query(VideoSequence).get(videoId) | |
| 32 print(vs.getDatabaseFilename()) | |
| 33 objects = storage.loadTrajectoriesFromSqlite(str(parentDir/vs.getDatabaseFilename()), 'object')#, args.nObjects, withFeatures = (params.useFeaturesForPrediction or predictionMethod == 'ps' or predictionMethod == 'mp')) | |
| 34 interactions = events.createInteractions(objects) | |
| 35 #if args.nProcesses == 1: | |
| 36 params = storage.ProcessParameters(str(parentDir/vs.cameraView.getTrackingConfigurationFilename())) | |
| 37 #print(interactions, True, args.computePET, predictionParameters, params.collisionDistance, params.predictionTimeHorizon, params.crossingZones) | |
| 38 processed = events.computeIndicators(interactions, True, args.computePET, predictionParameters, params.collisionDistance, params.predictionTimeHorizon, params.crossingZones, False, None) | |
| 39 storage.saveIndicatorsToSqlite(str(parentDir/vs.getDatabaseFilename()), processed) | |
| 40 | |
| 41 # else: | |
| 42 # pool = Pool(processes = args.nProcesses) | |
| 43 # nInteractionPerProcess = int(np.ceil(len(interactions)/float(args.nProcesses))) | |
| 44 # jobs = [pool.apply_async(events.computeIndicators, args = (interactions[i*nInteractionPerProcess:(i+1)*nInteractionPerProcess], not args.noMotionPrediction, args.computePET, predictionParameters, params.collisionDistance, params.predictionTimeHorizon, params.crossingZones, False, None)) for i in range(args.nProcesses)] | |
| 45 # processed = [] | |
| 46 # for job in jobs: | |
| 47 # processed += job.get() | |
| 48 # pool.close() |
