Skip to content

Commit 3bb4113

Browse files
author
Fabien Servant
committed
Update parallelization and log
1 parent 093d94d commit 3bb4113

2 files changed

Lines changed: 46 additions & 10 deletions

File tree

python/reducer.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def reduce_samples(inputSfMData, imagePairsList, samplesFolder, featuresFolder,
5050

5151
# Retrieve list of images pairs to process
5252
plist = avmic.PairSet()
53-
if not avmic.loadPairsFromFile(imagePairsList, plist, 0, -1, False):
53+
if not avmic.loadPairsFromFile(imagePairsList, plist, False):
5454
raise RuntimeError("Error in image pairs list loading")
5555

5656
# build a list of image pairs indexed by their reference images
@@ -72,38 +72,64 @@ def reduce_samples(inputSfMData, imagePairsList, samplesFolder, featuresFolder,
7272
for referenceId, pairs in plistByRef.items():
7373
logging.info(f"Processing reference #{referenceId}", flush=True)
7474

75+
# Output features file for the reference image
7576
path_coords = os.path.join(samplesFolder, str(referenceId) + ".npy")
7677

78+
# Load file with coordinates for a given reference view
79+
# This is an array of size [n, 3], where n is the number of coordinates used in this reference view
80+
# first column is the x coordinate
81+
# second column is the y coordinate
82+
# third column is the 1
83+
# fourth column is the scale
7784
try:
7885
coords_A_B = np.load(path_coords)
7986
except:
8087
coords_A_B = np.array(())
8188

89+
# Transform this array to a set of feature points for the reference view
90+
# referenceId may already exists in regionMap, because the reference view may have been used as
91+
# a matching view. We therefore return the offset in the list of features to be able to compute
92+
# indices for matches
8293
refOffset = export_features(regionsMap, referenceId, coords_A_B)
8394

95+
# For all pairs with the current reference view
8496
for item in pairs:
8597

8698
otherId = item[1]
8799

100+
# Load file with precomputed matches for a given reference view
101+
# This is an array of size [n, 3], where n is the number of matches
102+
# first column is the x coordinates in the other image
103+
# second column is the y coordinates in the other image
104+
# third column is the confidence score
105+
# fourth column is the scale
88106
path_samples = os.path.join(samplesFolder, str(referenceId) + "_" + str(otherId) + ".npy")
89107

90108
try:
91109
match_A_B = np.load(path_samples)
92110
except:
93111
continue
94112

113+
# Transform this array to a set of feature points for the other view
114+
# otherId may already exists in regionMap, because the view may have been used as
115+
# another matching view. We therefore return the offset in the list of features to be able to compute
116+
# indices for matches
95117
otherOffset = export_features(regionsMap, otherId, match_A_B)
96118

119+
# Build a list of matches using offset and indices
97120
pos = 0
98121
matches = avmatch.IndMatches()
99122
for rowId in range(0, match_A_B.shape[0]):
100123
if match_A_B[rowId, 2] > 1e-6:
101124
matches.append(avmatch.IndMatch(refOffset + rowId, otherOffset + pos))
102125
pos = pos + 1
103126

127+
# Save matches for pair per desc.
128+
# Obviously, here we only have on descriptor type
104129
perdesc = avmatch.MatchesPerDescType()
105130
perdesc[avmatch.EImageDescriberType_SIFT] = matches
106131

132+
# Save matches for pair per desc in a global container
107133
pair = avmatch.Pair(referenceId, otherId)
108134
global_matches[pair] = perdesc
109135

@@ -115,6 +141,8 @@ def reduce_samples(inputSfMData, imagePairsList, samplesFolder, featuresFolder,
115141
if __name__ == '__main__':
116142
import argparse
117143

144+
logger = logging.getLogger().setLevel(logging.INFO)
145+
118146
# create the top-level parser
119147
parser = argparse.ArgumentParser(prog='romaProcessor')
120148

python/sampler.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,8 @@ def compute_samples(inputSfMData, imagePairsList, warpFolder, certaintyFolder, s
254254
rangeIteration: if of chunk to compute between [0; rangeBlocksCount[
255255
rangeBlocksCount: count of chunks blocks
256256
"""
257-
257+
from pyalicevision import system as avsys
258+
258259
# First of all, load the optional filters
259260
filters = load_filters(filtersFolder)
260261

@@ -263,7 +264,7 @@ def compute_samples(inputSfMData, imagePairsList, warpFolder, certaintyFolder, s
263264

264265
# Retrieve list of images pairs to process
265266
plist = avmic.PairSet()
266-
if not avmic.loadPairsFromFile(imagePairsList, plist, 0, -1, False):
267+
if not avmic.loadPairsFromFile(imagePairsList, plist, False):
267268
raise RuntimeError("Error in image pairs list loading")
268269

269270
# build a list of image pairs indexed by their reference images
@@ -276,24 +277,29 @@ def compute_samples(inputSfMData, imagePairsList, warpFolder, certaintyFolder, s
276277
plistByRef[ref] = [item]
277278
refsToProcess = list(plistByRef)
278279

279-
#Compute parallelization
280-
blockSize = int(len(refsToProcess) / rangeBlocksCount)
281-
rangeStart = rangeIteration * blockSize
282-
rangeEnd = rangeStart + blockSize
283-
if rangeIteration + 1 == rangeBlocksCount:
284-
rangeEnd = len(refsToProcess)
280+
# Parallelization is done by splitting pairs based on their reference image
281+
# We want to have access to all the pairs from the same reference
282+
283+
# Computeing parallelization parameters
284+
(valid, rangeStart, rangeEnd) = avsys.rangeComputation(rangeIteration, rangeBlocksCount, len(refsToProcess))
285+
if not valid:
286+
logging.error("Range is out of bounds.")
287+
return
288+
285289
refsToProcess = refsToProcess[rangeStart:rangeEnd]
286290

287291
#Loop over all reference images
288292
for referenceId in refsToProcess:
289293

294+
# Retrieve all pairs for this reference image
290295
pairs = plistByRef[referenceId]
291296

292297
logging.info(f"Processing reference #{referenceId}", flush=True)
293298

294-
# Load uncertainties
299+
# Load uncertainties and store them using pair as key
295300
uncertaintiesByPair = build_uncertainties(iinfos, warpFolder, certaintyFolder, pairs, filters, minCertainty)
296301
if len(uncertaintiesByPair) == 0:
302+
logging.info("")
297303
continue
298304

299305
#If groupUncertainties, we sum the certainties together for the same reference image
@@ -358,6 +364,8 @@ def compute_samples(inputSfMData, imagePairsList, warpFolder, certaintyFolder, s
358364
if __name__ == '__main__':
359365
import argparse
360366

367+
logger = logging.getLogger().setLevel(logging.INFO)
368+
361369
# create the top-level parser
362370
parser = argparse.ArgumentParser(prog='romaProcessor')
363371

0 commit comments

Comments
 (0)