Paul-Edouard Sarlin commited on
Commit
0358e39
·
unverified ·
1 Parent(s): 47d67ab

Bugfixes when preparing the Mapillary dataset (#29)

Browse files

* Bugfix in inline loop order
* Don't save empty image infos
* Catch errors in API calls

maploc/data/mapillary/download.py CHANGED
@@ -89,7 +89,8 @@ class MapillaryDownloader:
89
  info = json.loads(path.read_text())
90
  else:
91
  info = await self.get_image_info(image_id)
92
- path.write_text(json.dumps(info))
 
93
  return info
94
 
95
  async def download_image_pixels_cached(self, url: str, path: Path):
@@ -102,7 +103,10 @@ class MapillaryDownloader:
102
  async def fetch_images_in_sequence(i, downloader):
103
  async with semaphore:
104
  info = await downloader.get_sequence_info(i)
105
- image_ids = [int(d["id"]) for d in info["data"]]
 
 
 
106
  return i, image_ids
107
 
108
 
@@ -111,7 +115,8 @@ async def fetch_images_in_sequences(sequence_ids, downloader):
111
  tasks = [fetch_images_in_sequence(i, downloader) for i in sequence_ids]
112
  for task in tqdm.asyncio.tqdm.as_completed(tasks):
113
  i, image_ids = await task
114
- seq_to_images_ids[i] = image_ids
 
115
  return seq_to_images_ids
116
 
117
 
 
89
  info = json.loads(path.read_text())
90
  else:
91
  info = await self.get_image_info(image_id)
92
+ if info is not None:
93
+ path.write_text(json.dumps(info))
94
  return info
95
 
96
  async def download_image_pixels_cached(self, url: str, path: Path):
 
103
  async def fetch_images_in_sequence(i, downloader):
104
  async with semaphore:
105
  info = await downloader.get_sequence_info(i)
106
+ if info is None:
107
+ image_ids = None
108
+ else:
109
+ image_ids = [int(d["id"]) for d in info["data"]]
110
  return i, image_ids
111
 
112
 
 
115
  tasks = [fetch_images_in_sequence(i, downloader) for i in sequence_ids]
116
  for task in tqdm.asyncio.tqdm.as_completed(tasks):
117
  i, image_ids = await task
118
+ if image_ids is not None:
119
+ seq_to_images_ids[i] = image_ids
120
  return seq_to_images_ids
121
 
122
 
maploc/data/mapillary/prepare.py CHANGED
@@ -252,7 +252,7 @@ def process_sequence(
252
  shots,
253
  disable=True,
254
  )
255
- shots_out = [(i, s) for i, ss in enumerate(shots_out) for s in ss if ss is not None]
256
 
257
  dump = {}
258
  for index, shot in shots_out:
 
252
  shots,
253
  disable=True,
254
  )
255
+ shots_out = [(i, s) for i, ss in enumerate(shots_out) if ss is not None for s in ss]
256
 
257
  dump = {}
258
  for index, shot in shots_out: