720 KiB
720 KiB
In [1]:
%matplotlib inline
import sys
sys.path.append('../../trajectron')
import os
import numpy as np
import torch
import dill
import json
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
import matplotlib.patheffects as pe
from helper import *
import visualization
Load nuScenes SDK and data¶
In [2]:
nuScenes_data_path = # Data Path to nuScenes data set
nuScenes_devkit_path = './devkit/python-sdk/'
sys.path.append(nuScenes_devkit_path)
from nuscenes.map_expansion.map_api import NuScenesMap
nusc_map = NuScenesMap(dataroot=nuScenes_data_path, map_name='boston-seaport')
In [3]:
line_colors = ['#375397','#80CBE5','#ABCB51','#F05F78', '#C8B0B0']
Map Encoding Demo¶
In [4]:
with open('../processed/nuScenes_test_full.pkl', 'rb') as f:
eval_env = dill.load(f, encoding='latin1')
eval_scenes = eval_env.scenes
In [5]:
ph = 6
log_dir = './models'
In [6]:
model_dir = os.path.join(log_dir, 'int_ee_me')
eval_stg, hyp = load_model(model_dir, eval_env, ts=12)
In [7]:
scene = eval_scenes[25]
scene.name
Out[7]:
In [8]:
# Define ROI in nuScenes Map
x_min = 773.0
x_max = 1100.0
y_min = 1231.0
y_max = 1510.0
In [9]:
layers = ['drivable_area',
'road_segment',
'lane',
'ped_crossing',
'walkway',
'stop_line',
'road_divider',
'lane_divider']
Prediction including Map Encoding¶
In [10]:
ph = 6
with torch.no_grad():
timestep = np.array([2])
predictions = eval_stg.predict(scene,
timestep,
ph,
num_samples=500)
predictions_mm = eval_stg.predict(scene,
timestep,
ph,
num_samples=1,
z_mode=True,
gmm_mode=True)
# Plot predicted timestep for random scene in map
my_patch = (x_min, y_min, x_max, y_max)
fig, ax = nusc_map.render_map_patch(my_patch, layers, figsize=(10, 10), alpha=0.1, render_egoposes_range=False)
ax.plot([], [], 'ko-',
zorder=620,
markersize=4,
linewidth=2, alpha=0.7, label='Ours (MM)')
ax.plot([],
[],
'w--o', label='Ground Truth',
linewidth=3,
path_effects=[pe.Stroke(linewidth=4, foreground='k'), pe.Normal()])
plot_vehicle_nice(ax,
predictions,
scene.dt,
max_hl=10,
ph=ph,
map=None, x_min=x_min, y_min=y_min)
plot_vehicle_mm(ax,
predictions_mm,
scene.dt,
max_hl=10,
ph=ph,
map=None, x_min=x_min, y_min=y_min)
ax.set_ylim((1385, 1435))
ax.set_xlim((850, 900))
leg = ax.legend(loc='upper right', fontsize=20, frameon=True)
ax.axis('off')
for lh in leg.legendHandles:
lh.set_alpha(.5)
ax.get_legend().remove()
fig.show()
fig.savefig('plots/qual_nuScenes_map_pos.pdf', dpi=300, bbox_inches='tight')
Prediction without Map Encoding¶
In [11]:
model_dir = os.path.join(log_dir, 'int_ee')
eval_stg_nm, hyp = load_model(model_dir, eval_env, ts=12)
In [12]:
ph = 6
with torch.no_grad():
timestep = np.array([2])
predictions = eval_stg_nm.predict(scene,
timestep,
ph,
num_samples=500)
predictions_mm = eval_stg_nm.predict(scene,
timestep,
ph,
num_samples=1,
z_mode=True,
gmm_mode=True)
# Plot predicted timestep for random scene in map
my_patch = (x_min, y_min, x_max, y_max)
fig, ax = nusc_map.render_map_patch(my_patch, layers, figsize=(10, 10), alpha=0.1, render_egoposes_range=False)
ax.plot([], [], 'ko-',
zorder=620,
markersize=4,
linewidth=2, alpha=0.7, label='Ours (MM)')
ax.plot([],
[],
'w--o', label='Ground Truth',
linewidth=3,
path_effects=[pe.Stroke(linewidth=4, foreground='k'), pe.Normal()])
plot_vehicle_nice(ax,
predictions,
scene.dt,
max_hl=10,
ph=ph,
map=None, x_min=x_min, y_min=y_min)
plot_vehicle_mm(ax,
predictions_mm,
scene.dt,
max_hl=10,
ph=ph,
map=None, x_min=x_min, y_min=y_min)
ax.set_ylim((1385, 1435))
ax.set_xlim((850, 900))
leg = ax.legend(loc='upper right', fontsize=20, frameon=True)
ax.axis('off')
for lh in leg.legendHandles:
lh.set_alpha(.5)
ax.get_legend().remove()
fig.show()
fig.savefig('plots/qual_nuScenes_no_map_pos.pdf', dpi=300, bbox_inches='tight')
Prediction using velocity output¶
In [18]:
model_dir = os.path.join(log_dir, 'ee_vel')
eval_stg_vel, hyp = load_model(model_dir, eval_env, ts=12)
In [19]:
ph = 6
with torch.no_grad():
timestep = np.array([2])
predictions = eval_stg_vel.predict(scene,
timestep,
ph,
num_samples=500)
predictions_mm = eval_stg_vel.predict(scene,
timestep,
ph,
num_samples=1,
z_mode=True,
gmm_mode=True)
# Plot predicted timestep for random scene in map
my_patch = (x_min, y_min, x_max, y_max)
fig, ax = nusc_map.render_map_patch(my_patch, layers, figsize=(10, 10), alpha=0.1, render_egoposes_range=False)
ax.plot([], [], 'ko-',
zorder=620,
markersize=4,
linewidth=2, alpha=0.7, label='Ours (MM)')
ax.plot([],
[],
'w--o', label='Ground Truth',
linewidth=3,
path_effects=[pe.Stroke(linewidth=4, foreground='k'), pe.Normal()])
plot_vehicle_nice(ax,
predictions,
scene.dt,
max_hl=10,
ph=ph,
map=None, x_min=x_min, y_min=y_min)
plot_vehicle_mm(ax,
predictions_mm,
scene.dt,
max_hl=10,
ph=ph,
map=None, x_min=x_min, y_min=y_min)
ax.set_ylim((1385, 1435))
ax.set_xlim((850, 900))
leg = ax.legend(loc='upper right', fontsize=20, frameon=True)
ax.axis('off')
for lh in leg.legendHandles:
lh.set_alpha(.5)
ax.get_legend().remove()
fig.show()
fig.savefig('plots/qual_nuScenes_no_map_vel.pdf', dpi=300, bbox_inches='tight')
Prediction using velocity output and map¶
In [15]:
model_dir = os.path.join(log_dir, 'me_vel')
eval_stg_vel_map, hyp = load_model(model_dir, eval_env, ts=12)
In [17]:
ph = 6
with torch.no_grad():
timestep = np.array([2])
predictions = eval_stg_vel_map.predict(scene,
timestep,
ph,
num_samples=500)
predictions_mm = eval_stg_vel_map.predict(scene,
timestep,
ph,
num_samples=1,
z_mode=True,
gmm_mode=True)
# Plot predicted timestep for random scene in map
my_patch = (x_min, y_min, x_max, y_max)
fig, ax = nusc_map.render_map_patch(my_patch, layers, figsize=(10, 10), alpha=0.1, render_egoposes_range=False)
ax.plot([], [], 'ko-',
zorder=620,
markersize=4,
linewidth=2, alpha=0.7, label='Ours (MM)')
ax.plot([],
[],
'w--o', label='Ground Truth',
linewidth=3,
path_effects=[pe.Stroke(linewidth=4, foreground='k'), pe.Normal()])
plot_vehicle_nice(ax,
predictions,
scene.dt,
max_hl=10,
ph=ph,
map=None, x_min=x_min, y_min=y_min)
plot_vehicle_mm(ax,
predictions_mm,
scene.dt,
max_hl=10,
ph=ph,
map=None, x_min=x_min, y_min=y_min)
ax.set_ylim((1385, 1435))
ax.set_xlim((850, 900))
leg = ax.legend(loc='upper right', fontsize=20, frameon=True)
ax.axis('off')
for lh in leg.legendHandles:
lh.set_alpha(.5)
ax.get_legend().remove()
fig.show()
fig.savefig('plots/qual_nuScenes_map_vel.pdf', dpi=300, bbox_inches='tight')
In [10]:
my_patch = (0, 0, 1, 1)
fig, ax = nusc_map.render_map_patch(my_patch, layers, figsize=(1, 1), alpha=0.1, render_egoposes_range=False)
ax.plot([], [], 'ko',
zorder=620,
markersize=4,
linewidth=2, alpha=0.7, label='Ours (ML)')
ax.plot([],
[],
'w--o', label='Ground Truth',
linewidth=3,
path_effects=[pe.Stroke(linewidth=4, foreground='k'), pe.Normal()])
leg = ax.legend(loc='upper left', fontsize=30, frameon=True)
for lh in leg.legendHandles:
lh.set_alpha(.5)
ax.axis('off')
ax.grid('off')
fig.savefig('plots/qual_nuScenes_legend.pdf', dpi=300, bbox_inches='tight')
In [ ]: