Skip to content

Commit 11a40c3

Browse files
author
spencer@primus
committed
Add get agent set and allow for getting objects in agent frame
1 parent 88ae083 commit 11a40c3

4 files changed

Lines changed: 22 additions & 26 deletions

File tree

avapi/__init__.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
# @Author: Spencer H
3-
# @Date: 2022-07-28
4-
# @Last Modified by: Spencer H
5-
# @Last Modified date: 2022-07-28
6-
# @Description:
7-
"""
8-
9-
"""
10-
111
import avapi.carla
122
import avapi.evaluation
133
import avapi.kitti

avapi/_dataset.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ def check_frame(self, frame):
124124
frame in self.frames
125125
), f"Candidate frame, {frame}, not in frame set {self.frames}"
126126

127+
def get_agent_set(self, frame: int) -> set:
128+
return self._load_agent_set(frame=frame)
129+
127130
def get_sensor_ID(self, sensor, agent=None):
128131
try:
129132
return self.sensor_IDs[sensor]

avapi/carla/__init__.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
# @Author: Spencer H
3-
# @Date: 2022-03-22
4-
# @Last Modified by: Spencer H
5-
# @Last Modified date: 2022-09-28
6-
# @Description:
7-
"""
8-
9-
"""
10-
111
from .dataset import CarlaScenesManager, get_splits_scenes
122

133

avapi/carla/dataset.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import numpy as np
77
from avstack import calibration
8+
from avstack.config import DATASETS
89
from avstack.datastructs import DataContainer, DataContainerDecoder
910
from avstack.environment import ObjectStateDecoder
1011
from avstack.geometry import GlobalOrigin3D, ReferenceFrame
@@ -61,6 +62,7 @@ def run_dataset_postprocessing(data_dir):
6162
_nominal_ignore_types = []
6263

6364

65+
@DATASETS.register_module()
6466
class CarlaScenesManager(BaseSceneManager):
6567
name = "CARLA"
6668
nominal_whitelist_types = _nominal_whitelist_types
@@ -239,17 +241,21 @@ def get_object_file(
239241
file_post = self.agent_files["frame"][frame]
240242
else:
241243
file_post = self.npc_files["frame"][frame]
242-
if sensor:
244+
if not is_global:
243245
file_post = file_post.replace("npcs", "objects")
244246
else:
245247
raise
246248
if is_global:
247249
filepath = os.path.join(self.obj_folder, file_post)
248250
else:
249-
assert sensor is not None
250-
filepath = os.path.join(
251-
self.obj_local_folder, f"{sensor}-{agent}", file_post
252-
)
251+
if sensor is None:
252+
filepath = os.path.join(
253+
self.obj_local_folder, f"agent-{agent}", file_post
254+
)
255+
else:
256+
filepath = os.path.join(
257+
self.obj_local_folder, f"{sensor}-{agent}", file_post
258+
)
253259
return filepath
254260

255261
def get_sensor_file(self, frame, timestamp, sensor, agent, file_type):
@@ -278,6 +284,10 @@ def get_agent(self, frame: int, agent: int):
278284
agents = self.get_agents(frame)
279285
return [ag for ag in agents if ag.ID == agent][0]
280286

287+
def _load_agent_set(self, frame: int) -> set:
288+
# TODO: this is slow...improve
289+
return {ag.ID for ag in self.get_agents(frame)}
290+
281291
def get_sensor_ID(self, sensor: str, agent: int):
282292
return f"{sensor}-{agent}"
283293

@@ -299,7 +309,7 @@ def _load_frames(self, sensor: str, agent: int):
299309
return self.sensor_frames[agent][sensor]
300310

301311
def _load_timestamp(self, frame, sensor=None, agent=None, utime=False):
302-
if (sensor is None) and (agent is None):
312+
if sensor is None:
303313
return self.timestamps[self.frames == frame][0]
304314
else:
305315
return self.sensor_frame_to_ts[agent][sensor][frame]
@@ -411,6 +421,9 @@ def _load_objects_global(
411421
agent.change_reference(GlobalOrigin3D, inplace=False)
412422
for agent in self.get_agents(frame)
413423
]
424+
# HACK: alter the ID of the agents to mitigate conflict
425+
for agent in agents_as_objects:
426+
agent.ID += 99999
414427
if ignore_static_agents:
415428
agents_as_objects = [
416429
agent

0 commit comments

Comments
 (0)