Skip to content

Commit

Permalink
Re-export all nuScenes tutorials (nutonomy#478)
Browse files Browse the repository at this point in the history
* Outputs for map_expansion_tutorial.ipynb

* Outputs for nuimages_tutorial.ipynb

* Outputs for nuscenes_lidarseg_tutorial.ipynb

* Outputs for nuscenes_tutorial.ipynb

* Outputs for prediction_tutorial.ipynb

* Fix typo in LidarSegEval

* Compare with gt if available when validating no. of points in preds

* Allow print_all_message_stats in can bus to print partial only

* Outputs for can_bus_tutorial.ipynb

* Clear output from tutorials
  • Loading branch information
whyekit-motional authored Nov 9, 2020
1 parent 53a9015 commit dd7205d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 13 deletions.
11 changes: 9 additions & 2 deletions python-sdk/nuscenes/can_bus/can_bus_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,23 @@ def __init__(self,
self.all_messages = self.can_messages + self.derived_messages

def print_all_message_stats(self,
scene_name: str) -> None:
scene_name: str,
print_full: bool = False) -> None:
"""
Prints the meta stats for each CAN message type of a particular scene.
:param scene_name: The name of the scene, e.g. scene-0001.
:param print_full: Whether to show all stats for all message types in the scene.
"""
all_messages = {}
for message_name in self.can_messages:
messages = self.get_messages(scene_name, 'meta')
all_messages[message_name] = messages
print(json.dumps(all_messages, indent=2))

if print_full:
print(json.dumps(all_messages, indent=2))
else:
partial_messages = {message: list(stats.keys()) for message, stats in all_messages.items()}
print(json.dumps(partial_messages, indent=2))

def print_message_stats(self,
scene_name: str,
Expand Down
2 changes: 1 addition & 1 deletion python-sdk/nuscenes/eval/lidarseg/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def __init__(self,
self.eval_set = eval_set
self.verbose = verbose

self.mapper = LidarsegClassMapper(nusc_)
self.mapper = LidarsegClassMapper(self.nusc)
self.ignore_idx = self.mapper.ignore_class['index']
self.id2name = {idx: name for name, idx in self.mapper.coarse_name_2_coarse_idx_mapping.items()}
self.num_classes = len(self.mapper.coarse_name_2_coarse_idx_mapping)
Expand Down
24 changes: 16 additions & 8 deletions python-sdk/nuscenes/eval/lidarseg/validate_submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,24 @@ def validate_submission(nusc: NuScenes, results_folder: str, eval_set: str, verb
'Error: The prediction .bin file {} does not exist.'.format(lidarseg_pred_filename)
lidarseg_pred = np.fromfile(lidarseg_pred_filename, dtype=np.uint8)

# Check number of points in the point cloud.
pointsensor = nusc.get('sample_data', sd_token)
pcl_path = os.path.join(nusc.dataroot, pointsensor['filename'])
pc = LidarPointCloud.from_file(pcl_path)
points = pc.points

assert points.shape[1] == len(lidarseg_pred), \
# Check number of predictions for the point cloud.
if len(nusc.lidarseg) > 0: # If ground truth exists, compare the no. of predictions with that of ground truth.
lidarseg_label_filename = os.path.join(results_bin_folder, sd_token + '_lidarseg.bin')
assert os.path.exists(lidarseg_pred_filename), \
'Error: The ground truth .bin file {} does not exist.'.format(lidarseg_label_filename)
lidarseg_label = np.fromfile(lidarseg_label_filename, dtype=np.uint8)
num_points = len(lidarseg_label)
else: # If no ground truth is available, compare the no. of predictions with that of points in a point cloud.
pointsensor = nusc.get('sample_data', sd_token)
pcl_path = os.path.join(nusc.dataroot, pointsensor['filename'])
pc = LidarPointCloud.from_file(pcl_path)
points = pc.points
num_points = points.shape[1]

assert num_points == len(lidarseg_pred), \
'Error: There are {} predictions for lidar sample data token {} ' \
'but there are only {} points in the point cloud.'\
.format(sd_token, len(lidarseg_pred), points.shape[1])
.format(sd_token, len(lidarseg_pred), num_points)

assert all((lidarseg_pred > 0) & (lidarseg_pred < num_classes)), \
"Error: Array for predictions in {} must be between 1 and {} (inclusive)."\
Expand Down
2 changes: 1 addition & 1 deletion python-sdk/tutorials/can_bus_tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.6"
"version": "3.7.7"
},
"pycharm": {
"stem_cell": {
Expand Down
2 changes: 1 addition & 1 deletion python-sdk/tutorials/prediction_tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"metadata": {},
"source": [
"# nuScenes prediction tutorial\n",
"<img src=\"trajectory.gif\" width=\"300\" align=\"left\">"
"<img src=\"https://www.nuscenes.org/public/tutorials/trajectory.gif\" width=\"300\" align=\"left\">"
]
},
{
Expand Down

0 comments on commit dd7205d

Please sign in to comment.