-
Notifications
You must be signed in to change notification settings - Fork 629
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consecutive scenes #900
Comments
@Alt216 you could try something like this: from typing import List
import numpy as np
from nuscenes.nuscenes import NuScenes
def get_scenes_per_log(nusc: NuScenes):
scenes_per_log = {}
for scene in nusc.scene:
log_token = scene['log_token']
scene_token = scene['token']
if log_token not in scenes_per_log:
scenes_per_log[log_token] = [scene_token]
else:
scenes_of_log = scenes_per_log[log_token]
scenes_of_log.append(scene_token)
scenes_per_log[log_token] = scenes_of_log
assert len(nusc.scene) == sum([len(scenes) for scenes in scenes_per_log.values()])
assert len(nusc.log) == len(scenes_per_log)
return scenes_per_log
def sort_scenes_by_timestamp(nusc: NuScenes, list_of_scene_tokens: List[str]):
"""
Sort a given list of scene tokens in temporal order. Assume scenes do not overlap within a log
(this should be the case in nuScenes).
"""
# Get the timestamp of each scene's first sample.
scene_first_sample_timestamps = []
for scene_token in list_of_scene_tokens:
scene = nusc.get('scene', scene_token)
scene_first_sample_token = scene['first_sample_token']
scene_first_sample = nusc.get('sample', scene_first_sample_token)
scene_first_sample_timestamps.append(scene_first_sample['timestamp'])
# Sort the scenes based on the timestamp of their respective first samples.
sorted_idxs = np.argsort(scene_first_sample_timestamps)
return [list_of_scene_tokens[i] for i in sorted_idxs]
nusc_ = NuScenes(version='v1.0-mini', dataroot='/data/sets/nuscenes', verbose=False)
some_scenes_per_log = get_scenes_per_log(nusc_)
some_scenes_per_log_sorted = {}
for log_token, scene_tokens_of_log in some_scenes_per_log.items():
some_scenes_per_log_sorted[log_token] = sort_scenes_by_timestamp(nusc_, scene_tokens_of_log)
print(some_scenes_per_log_sorted) The above code snippet will return a dictionary in which each key is a log token, and each value is a list of scene tokens (sorted in temporal order) which belong to the corresponding log token, e.g.:
To get the length of each scene, you could simply get the difference between the timestamp of the last sample in a scene, and the first sample in the same scene (I'll leave that as an exercise for you to implement the code) |
Hi, is there a way to get consecutive scenes from the same map?
Also how can we determine the length of a particular scene.
The text was updated successfully, but these errors were encountered: