Skip to content

Commit

Permalink
MAJOR Refactor opentraj toolkit
Browse files Browse the repository at this point in the history
  • Loading branch information
amiryanj committed Mar 30, 2021
1 parent 79be733 commit 55e2ebe
Show file tree
Hide file tree
Showing 75 changed files with 219 additions and 7 deletions.
19 changes: 19 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
The MIT License (MIT)
Copyright (c) 2020-2021 CrowdBot

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in the
Software without restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2 changes: 0 additions & 2 deletions doc/trajnet_graph.py

This file was deleted.

File renamed without changes.
File renamed without changes.
Binary file not shown.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
58 changes: 58 additions & 0 deletions docs/trajnet_graph.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Author: Javad Amirian
# Email: [email protected]

import datetime
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib
from adjustText import adjust_text
import matplotlib.dates as mdates
# import seaborn as sns
# matplotlib.use('TkAgg')

# Read the table
table_file = '/home/cyrus/Dropbox/OpenTraj-paper/presentation/trajnet-leaders.xls'
data = pd.read_excel(table_file, header=0)
ADEs = data["ADE"]
FDEs = data["FDE"]
date_objs = []
for date in data["Date"]:
year_month = date.split('-')
date_obj = datetime.datetime(year=int(year_month[0]), month=int(year_month[1]), day=1)
date_objs.append(date_obj)
dates = matplotlib.dates.date2num(date_objs)

# Plots
fig, ax = plt.subplots(nrows=1, ncols=1)

# matplotlib.pyplot.plot_date(dates, FDEs, 'bx', label="FDE")
# name_texts = [plt.text(dates[i], FDEs[i], pred_name, horizontalalignment='center')
# for i, pred_name in enumerate(data["Predictor"])]

matplotlib.pyplot.plot_date(dates, ADEs, 'bo',
label="Average Displacement Error")
name_texts = [plt.text(dates[i], ADEs[i], pred_name,
color="magenta" if "DCNet" in pred_name else "black")
for i, pred_name in enumerate(data["Predictor"])]
plt.ylim([0.21, 0.53])
arrows = adjust_text(name_texts, arrowprops=dict(arrowstyle='->', color='red'))

plt.grid(axis='both', linestyle='--')
plt.ylabel("Prediction Error", fontweight='bold')


plt.xlim([min(dates)-500, max(dates) + 300])
plt.xticks([datetime.datetime(1995, 1, 1),
datetime.datetime(2016, 1, 1),
datetime.datetime(2018, 1, 1),
datetime.datetime(2019, 1, 1),
datetime.datetime(2020, 1, 1),
datetime.datetime(2021, 1, 1)], rotation=45)
myFmt = mdates.DateFormatter('%Y')
ax.xaxis.set_major_formatter(myFmt)
plt.xlabel("Origin of the Idea", labelpad=-15, fontweight='bold')

ax.set_facecolor((0.90, 0.97, 0.82))
plt.legend(loc="lower left")
plt.title("Trajnet Benchmark (World Plane Human-Human Dataset)")
plt.show()
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ def run(trajlets, opentraj_root, output_dir):
'multimodality indicators.')
parser.add_argument('--opentraj_root', '--root')
parser.add_argument('--output_dir', '--output')
parser.add_argument('--execution', '--exec',
parser.add_argument('--execution', '--exe',
default='normal',
choices=['normal', 'parallelized'],
help='pick a execution (default: "vae")')
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,13 @@ def load_crowds(path, **kwargs):
zara_01_vsp = os.path.join(OPENTRAJ_ROOT, 'datasets/UCY/zara01/annotation.vsp')
zara_hmg_file = os.path.join(OPENTRAJ_ROOT, 'datasets/UCY/zara01/H.txt')
zara_01_ds = load_crowds(zara_01_vsp, use_kalman=False, homog_file=zara_hmg_file)
trajs = zara_01_ds.get_trajectories()
trajs = [g for _, g in trajs]
# trajs = zara_01_ds.get_trajectories()
# trajs = [g for _, g in trajs]
trajs = zara_01_ds.data.groupby(["scene_id", "agent_id"])
trajs = [(scene_id, agent_id, tr) for (scene_id, agent_id), tr in trajs]
for scene_id, agent_id, traj in trajs:
cur_locs.append(traj[traj["timestamp"] <= cur_time].iloc)

samples = zara_01_ds.get_entries()
plt.scatter(samples["pos_x"], samples["pos_y"])
plt.show()
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def get_trajlets(opentraj_root, dataset_names, to_numpy=True):
# ================================================================
# ===================== Load the datasets ========================
# ================================================================
def get_datasets(opentraj_root, dataset_names):
def get_datasets(opentraj_root, dataset_names, use_kalman='default'):
datasets = {}

# Make a temp dir to store and load trajdatasets (no postprocess anymore)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
115 changes: 115 additions & 0 deletions opentraj/toolkit/ui/ui_dash.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# Author: Javad Amirian
# Email: [email protected]

# Run this app with `python app.py` and
import os
import numpy as np
import pandas as pd

import dash
import dash_core_components as dcc
import dash_html_components as html
import dash_bootstrap_components as dbc
import plotly.express as px
import plotly.graph_objects as go
from dash.dependencies import Input, Output

from toolkit.loaders.loader_crowds import load_crowds
from toolkit.benchmarking.load_all_datasets import all_dataset_names, get_datasets, get_trajlets

# Application
# ===========================================
# see https://plotly.com/python/px-arguments/ for more options
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
# ----------------------


# default values
# ----------------------
traj_dataset = pd.DataFrame({})
cur_time = 0
time_horizon = [-4.8, 4.8]
traj_fig = go.Figure()
graph_height = 800
time_horizon_marks = [0.4, 0.8, 1.6, 3.2, 4.8, 9.6]
time_horizon_marks = [-x for x in time_horizon_marks[::-1]] + [0] + time_horizon_marks
cur_time_slider = dcc.Slider(id='cur_time', min=0, max=1000, step=0.1, value=0, updatemode='drag')

# Biuld the layout
# dbc.Spinner()
app.layout = html.Div(children=[
html.H2('OpenTraj'),
html.H5('Benchmarking Human Trajectory Prediction Datasets'),
html.Hr(),
dbc.Container(['OpenTraj Root: ',
dcc.Input(id='opentraj_root', type='text', spellCheck='false',
placeholder='Enter path to the root directory of OpenTraj',
# value='Enter the path to the root directory of OpenTraj',
value='/home/cyrus/workspace2/OpenTraj',
inputMode="url", style={'width': 360})],
fluid=True, id='opentraj_root_container'),
dcc.Dropdown(id='select_dataset', placeholder='Select Dataset...',
options=[{'label': ds_name, 'value': ds_name} for ds_name in all_dataset_names], multi=False),
dcc.Graph(id='traj_graph', figure=traj_fig, style={'height': graph_height}),
cur_time_slider,
dcc.RangeSlider(id='time_horizon', min=time_horizon_marks[0], max=time_horizon_marks[-1], step=0.1,
marks=dict(
zip(time_horizon_marks, ['%s%.1fs' % (["", "+"][x > 0.001], x) for x in time_horizon_marks])),
value=[-4.8, 4.8], updatemode='drag')
])


@app.callback(Output('cur_time', 'max'),
Input('opentraj_root', 'value'),
Input('select_dataset', 'value'))
def load_dataset(opentraj_root, dataset_name):
if os.path.exists(opentraj_root) \
and os.path.exists(os.path.join(opentraj_root, 'datasets')) and dataset_name:
global traj_dataset, traj_fig, cur_time
cur_time = 0
traj_datasets = get_datasets(opentraj_root, [dataset_name])
if dataset_name in traj_datasets:
traj_dataset = traj_datasets[dataset_name].data
return np.max(traj_dataset["timestamp"])
return 0


@app.callback(Output('traj_graph', 'figure'),
Input('cur_time', 'value'),
Input('time_horizon', 'value'),
Input('opentraj_root', 'value'),
Input('select_dataset', 'value')
)
def update_graph(cur_time_, time_horizon_, _, __):
global cur_time, time_horizon
cur_time, time_horizon = cur_time_, time_horizon_
fig = go.Figure()
if len(traj_dataset):
print("Scatter Trajs...")
selected_data = traj_dataset[(traj_dataset["timestamp"] >= cur_time + time_horizon[0])
& (traj_dataset["timestamp"] <= cur_time + time_horizon[1])]
print("len selected data = ", len(selected_data))
trajs = selected_data.groupby(["scene_id", "agent_id"])
trajs = [(scene_id, agent_id, tr) for (scene_id, agent_id), tr in trajs]

cur_poss = []
for scene_id, agent_id, traj in trajs:
fig.add_scatter(x=traj["pos_x"], y=traj["pos_y"], name="%s[%d]" % (scene_id, agent_id),
mode="lines+markers")
if len(traj):
# print(agent_id)
# print(traj[traj["timestamp"] <= cur_time])
cur_poss.append(traj[traj["timestamp"] <= cur_time].iloc[-1][["pos_x", "pos_y"]].to_numpy())
cur_poss = np.stack(cur_poss)
fig.add_scatter(x=cur_poss[:, 0], y=cur_poss[:, 1], mode="markers", showlegend=False)
fig['layout']['xaxis'].update(title='', range=[np.min(traj_dataset["pos_x"]), np.max(traj_dataset["pos_x"])],
dtick=2.5, autorange=False)
fig['layout']['yaxis'].update(title='', range=[np.min(traj_dataset["pos_y"]), np.max(traj_dataset["pos_y"])],
dtick=2.5, autorange=False)
fig.update_yaxes(scaleanchor="x", scaleratio=1)
return fig


if __name__ == '__main__':
app.run_server(debug=True, port=8051)
2 changes: 1 addition & 1 deletion toolkit/ui/play.py → opentraj/toolkit/ui/ui_pyqt.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,4 +285,4 @@ def play(self, traj_dataset, Hinv, media_file):

play = Play(args.gui_mode)
play.play(traj_dataset, Hinv, media_file)
# qtui.app.exec()
# qtui.app.exe()
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
17 changes: 17 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from setuptools import setup

setup(
name='opentraj',
version='0.1.0',
author='Javad Amirian',
author_email='[email protected]',
packages=['package_name', 'package_name.test'],
scripts=['bin/script1','bin/script2'],
url='https://github.com/crowdbotp/OpenTraj',
license='MIT',
description='Tools for working with trajectory datasets',
long_description=open('README.txt').read(),
install_requires=[
"pytest",
],
)

0 comments on commit 55e2ebe

Please sign in to comment.