Mercurial > hg > nsaunier > traffic-intelligence
comparison scripts/nomad/site-parameters-optimization.py @ 1221:5a207c838323
correcting recursive errors
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Mon, 19 Jun 2023 22:37:45 -0400 |
| parents | 8a626226793e |
| children | 051cf5bddc1f |
comparison
equal
deleted
inserted
replaced
| 1220:2dc9899b73ae | 1221:5a207c838323 |
|---|---|
| 5 from trafficintelligence import storage, moving | 5 from trafficintelligence import storage, moving |
| 6 import subprocess | 6 import subprocess |
| 7 import numpy as np | 7 import numpy as np |
| 8 | 8 |
| 9 | 9 |
| 10 def loadParametersStartProcess(filename, intersections): | 10 def loadParameters(filename): |
| 11 # load initial parameters from x.txt | 11 # load initial parameters from x.txt |
| 12 f = open(filename, 'r+') | 12 f = open(filename, 'r+') |
| 13 l = f.readline() | 13 l = f.readline() |
| 14 x = [s for s in l.strip().split(" ")] | 14 x = [s for s in l.strip().split(" ")] |
| 15 f.close() | 15 f.close() |
| 16 | 16 |
| 17 # create para-value list | 17 # create para-value list |
| 18 para = paraValueList(x) | 18 return paraValueList(x) |
| 19 | 19 |
| 20 # run process including trackingfeature, groupfeature, load groundtruth, compute mota | |
| 21 print(process(para, intersections)) | |
| 22 | |
| 23 def paraValueList(x): | 20 def paraValueList(x): |
| 24 #create para-value list | 21 #create para-value list |
| 25 #list of the 8 parameters and their values | 22 #list of the 8 parameters and their values |
| 26 p = 8*[None] | 23 p = 8*[None] |
| 27 p[0] = '--feature-quality' #]0.-0.4] | 24 p[0] = '--feature-quality' #]0.-0.4] |
| 41 for n in range(len(x)): | 38 for n in range(len(x)): |
| 42 para = para + [p[n],x[n]] | 39 para = para + [p[n],x[n]] |
| 43 | 40 |
| 44 return para | 41 return para |
| 45 | 42 |
| 46 def process(para, intersections): | 43 def process(para, intersections, recursive): |
| 47 Mota = [] | 44 Mota = [] |
| 48 gtDatabaseaAbsPaths = [] | 45 gtDatabaseaAbsPaths = [] |
| 49 configFileAbsPaths = [] | 46 configFileAbsPaths = [] |
| 50 | 47 |
| 51 cwd = os.getcwd() | 48 cwd = os.getcwd() |
| 52 # move to the location of the intersection | 49 # move to the location of the intersection |
| 53 for intersectionPath in intersections: | 50 for intersectionPath in intersections: |
| 54 intersectionAbsPath = os.path.abspath(intersectionPath) | 51 intersectionAbsPath = os.path.abspath(intersectionPath) |
| 55 os.chdir(intersectionAbsPath) | 52 os.chdir(intersectionAbsPath) |
| 56 # iterate through all the subdirectories to find ground truth sqlite files | 53 # iterate through all the subdirectories to find ground truth sqlite files |
| 57 newPaths = [os.path.abspath(intersectionAbsPath + '/' + file) for file in glob.glob('**/*_gt.sqlite', recursive=True)] | 54 newPaths = [os.path.abspath(fn) for fn in glob.glob(intersectionAbsPath+'/*_gt.sqlite', recursive=recursive)] |
| 58 gtDatabaseaAbsPaths.extend(newPaths) | 55 gtDatabaseaAbsPaths.extend(newPaths) |
| 59 configFilename = os.path.abspath(intersectionAbsPath + '/' + glob.glob('*.cfg', recursive=True)[0]) | 56 configFilename = os.path.abspath(glob.glob(intersectionAbsPath+'/*.cfg', recursive=recursive)[0]) |
| 60 configFileAbsPaths.extend([configFilename]*len(newPaths)) | 57 configFileAbsPaths.extend([configFilename]*len(newPaths)) |
| 61 os.chdir(cwd) | 58 os.chdir(cwd) |
| 62 for gtDatabaseAbsPath, configFileAbsPath in zip(gtDatabaseaAbsPaths, configFileAbsPaths): | 59 for gtDatabaseAbsPath, configFileAbsPath in zip(gtDatabaseaAbsPaths, configFileAbsPaths): |
| 63 gtDatabaseBasename = gtDatabaseAbsPath[:-10] | 60 gtDatabaseBasename = gtDatabaseAbsPath[:-10] |
| 64 videoFilename = gtDatabaseBasename + ".avi" # careful, it may be necessary to check video type / extension | 61 videoFilename = gtDatabaseBasename + ".avi" # careful, it may be necessary to check video type / extension |
| 114 # intersections = args[0] | 111 # intersections = args[0] |
| 115 # optimizeGroupingOnly = eval(args[1]) | 112 # optimizeGroupingOnly = eval(args[1]) |
| 116 # intersections = eval(intersections) | 113 # intersections = eval(intersections) |
| 117 | 114 |
| 118 # Just write the intersections to optimize here | 115 # Just write the intersections to optimize here |
| 119 intersections = ['../12-laurier'] | 116 intersections = ['.']#['/home/nicolas/Research/Data/montreal/12-07-laurier'] |
| 117 recursive = False | |
| 120 | 118 |
| 121 loadParametersStartProcess(sys.argv[1], intersections) | 119 para = loadParameters(sys.argv[1]) |
| 120 # run process including trackingfeature, groupfeature, load groundtruth, compute mota | |
| 121 print(process(para, intersections, recursive)) | |
| 122 sys.exit(0) | 122 sys.exit(0) |
