Skip to content

Commit 57d6d23

Browse files
author
Tianhao Wu
committed
reformat and add colab running button
1 parent 2578dc0 commit 57d6d23

10 files changed

+47
-20
lines changed

Makefile

+9
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,12 @@ help:
1818
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
1919
%: Makefile
2020
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
21+
22+
html-noplot:
23+
$(SPHINXBUILD) -D plot_gallery=0 -b html $(ALLSPHINXOPTS) $(SOURCEDIR) $(BUILDDIR)/html
24+
@echo
25+
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
26+
27+
clean:
28+
rm -rf $(BUILDDIR)/*
29+
rm -rf beginner/ advanced/ intermediate/ imu/ dynamics/ pgo/

conf.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
author = 'PyPose contributors'
2323

2424
# The full version, including alpha/beta/rc tags
25-
release = 'v0.1'
25+
import pypose
26+
version = pypose.__version__
2627

2728

2829
# -- General configuration ---------------------------------------------------
@@ -36,9 +37,9 @@
3637

3738

3839
sphinx_gallery_conf = {
39-
'examples_dirs': ['beginner_source', 'intermediate_source',
40-
'advanced_source'],
41-
'gallery_dirs': ['beginner', 'intermediate', 'advanced'],
40+
'examples_dirs': ['beginner_source', 'dynamics_source', 'imu_source',
41+
'pgo_source'],
42+
'gallery_dirs': ['beginner', 'dynamics', 'imu', 'pgo'],
4243
'filename_pattern': 'tutorial.py',
4344
}
4445

@@ -60,7 +61,11 @@
6061

6162
html_theme = 'pypose_sphinx_theme'
6263
html_theme_path = [pypose_sphinx_theme.get_html_theme_path()]
63-
64+
html_theme_options = {
65+
'pytorch_project': 'tutorials',
66+
'collapse_navigation': False,
67+
'display_version': True,
68+
}
6469

6570
# Add any paths that contain custom static files (such as style sheets) here,
6671
# relative to this directory. They are copied after the builtin static files,

dynamics_source/cartpole_tutorial.py

+2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def createTimePlot(x, y, figname="Un-named plot", title=None, xlabel=None, ylabe
7171

7272
time = torch.arange(0, N+1) * dt
7373
input = torch.sin(time)
74+
7475
######################################################################
7576
# Initial state
7677

@@ -100,6 +101,7 @@ def createTimePlot(x, y, figname="Un-named plot", title=None, xlabel=None, ylabe
100101

101102
######################################################################
102103
# Jacobian computation - Find jacobians at the last step
104+
103105
jacob_state, jacob_input = state_all[-1,:].T, input[-1]
104106
cartPoleSolver.set_refpoint(state=jacob_state, input=jacob_input.unsqueeze(0), t=time[-1])
105107
A = cartPoleSolver.A

dynamics_source/floquet_tutorial.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ def createTimePlot(x, y, figname="Un-named plot", title=None, xlabel=None, ylabe
4848
######################################################################
4949
# Number of time steps
5050
# ---------------------
51+
5152
N = 100
5253

5354

5455
######################################################################
5556
# Time, Input, Initial state
5657

57-
5858
time = torch.arange(0, N+1)
5959
input = torch.sin(2*math.pi*time/50)
6060
state = torch.tensor([1., 1.])
@@ -78,6 +78,7 @@ def createTimePlot(x, y, figname="Un-named plot", title=None, xlabel=None, ylabe
7878

7979
######################################################################
8080
# Create time plots to show dynamics
81+
8182
f, ax = plt.subplots(nrows=4, sharex=True)
8283
for _i in range(2):
8384
ax[_i].plot(time, state_all[:,_i], label='pp')
@@ -90,12 +91,14 @@ def createTimePlot(x, y, figname="Un-named plot", title=None, xlabel=None, ylabe
9091

9192
######################################################################
9293
# Jacobian computation - Find jacobians at the last step
94+
9395
vars = ['A', 'B', 'C', 'D', 'c1', 'c2']
9496
solver.set_refpoint()
9597
[print(_v, getattr(solver, _v)) for _v in vars]
9698

9799
######################################################################
98100
# Jacobian computation - Find jacobians at the 5th step
101+
99102
idx = 5
100103
solver.set_refpoint(state=state_all[idx], input=input[idx], t=time[idx])
101104
[print(_v, getattr(solver, _v)) for _v in vars]

dynamics_source/neuralnet_tutorial.py

+2
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,13 @@ def createTimePlot(x, y, figname="Un-named plot", title=None, xlabel=None, ylabe
3939

4040
######################################################################
4141
# Time Step
42+
4243
dt = 0.01 # Time step size
4344
N = 1000 # Number of time steps
4445

4546
######################################################################
4647
# Time and input
48+
4749
time = torch.arange(0, N + 1) * dt
4850
input = torch.sin(time)
4951

imu_source/imu_corrector_tutorial.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
import tqdm, argparse
1111
import torch.utils.data as Data
1212
from torch.optim.lr_scheduler import ReduceLROnPlateau
13-
from imu_dataset import KITTI_IMU, imu_collate, move_to
13+
from imu_dataset_tutorial import KITTI_IMU, imu_collate, move_to
1414

1515

1616
######################################################################
17-
# Preparation
18-
# ------------
17+
# Define IMU Corrector
18+
# -----------------------
1919

2020
class IMUCorrector(nn.Module):
2121
def __init__(self, size_list= [6, 64, 128, 128, 128, 6]):
@@ -102,7 +102,7 @@ def test(network, loader, device = "cuda:0"):
102102
parser.add_argument("--device", type=str, default='cuda:0', help="cuda or cpu")
103103
parser.add_argument("--batch-size", type=int, default=4, help="batch size")
104104
parser.add_argument("--max_epoches", type=int, default=100, help="max_epoches")
105-
parser.add_argument("--dataroot", type=str, default='./examples/module/imu', help="dataset location downloaded")
105+
parser.add_argument("--dataroot", type=str, default='../dataset', help="dataset location downloaded")
106106
parser.add_argument("--dataname", type=str, default='2011_09_26', help="dataset name")
107107
parser.add_argument("--datadrive", nargs='+', type=str, default=[ "0001"], help="data sequences")
108108
parser.add_argument('--load_ckpt', default=False, action="store_true")
@@ -114,7 +114,7 @@ def test(network, loader, device = "cuda:0"):
114114
test_loader = Data.DataLoader(dataset=test_dataset, batch_size=args.batch_size, collate_fn=imu_collate, shuffle=False)
115115

116116
######################################################################
117-
# optimizer
117+
# Optimizer
118118

119119
network = IMUCorrector().to(args.device)
120120
optimizer = torch.optim.Adam(network.parameters(), lr = 5e-6) # to use with ViTs
File renamed without changes.

imu_source/imu_integrator_tutorial.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import matplotlib.pyplot as plt
1616
from matplotlib.patches import Ellipse
1717
from matplotlib.collections import PatchCollection
18-
from imu_dataset import KITTI_IMU, imu_collate, move_to
18+
from imu_dataset_tutorial import KITTI_IMU, imu_collate, move_to
1919

2020

2121
######################################################################
@@ -42,8 +42,8 @@ def plot_gaussian(ax, means, covs, color=None, sigma=3):
4242
parser.add_argument("--integrating-step", type=int, default=1, help="number of integrated steps")
4343
parser.add_argument("--batch-size", type=int, default=1, help="batch size, only support 1 now")
4444
parser.add_argument("--step-size", type=int, default=2, help="the size of the integration for one interval")
45-
parser.add_argument("--save", type=str, default='./examples/module/imu/save/', help="location of png files to save")
46-
parser.add_argument("--dataroot", type=str, default='./examples/module/imu/', help="dataset location downloaded")
45+
parser.add_argument("--save", type=str, default='../dataset/save/', help="location of png files to save")
46+
parser.add_argument("--dataroot", type=str, default='../dataset/', help="dataset location downloaded")
4747
parser.add_argument("--dataname", type=str, default='2011_09_26', help="dataset name")
4848
parser.add_argument("--datadrive", nargs='+', type=str, default=["0001","0002","0005","0009","0011",
4949
"0013","0014","0015","0017","0018","0019","0020","0022","0005"], help="data sequences")
File renamed without changes.

pgo_source/pgo_tutorial.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import argparse
1111
import pypose as pp
1212
from torch import nn
13-
from pgo_dataset import G2OPGO
13+
from pgo_dataset_tutorial import G2OPGO
1414
import matplotlib.pyplot as plt
1515
import pypose.optim.solver as ppos
1616
import pypose.optim.kernel as ppok
@@ -20,8 +20,9 @@
2020

2121

2222
######################################################################
23-
# Preparation
24-
# ------------
23+
# Define Pose Graph
24+
# ------------------
25+
2526
class PoseGraph(nn.Module):
2627

2728
def __init__(self, nodes):
@@ -54,18 +55,22 @@ def plot_and_save(points, pngname, title='', axlim=None):
5455
parser = argparse.ArgumentParser(description='Pose Graph Optimization')
5556
parser.add_argument("--device", type=str, default='cuda:0', help="cuda or cpu")
5657
parser.add_argument("--radius", type=float, default=1e4, help="trust region radius")
57-
parser.add_argument("--save", type=str, default='./examples/module/pgo/save/', help="files location to save")
58-
parser.add_argument("--dataroot", type=str, default='./examples/module/pgo/pgodata', help="dataset location")
58+
parser.add_argument("--save", type=str, default='../dataset/pgo/save/', help="files location to save")
59+
parser.add_argument("--dataroot", type=str, default='../dataset/pgo', help="dataset location")
5960
parser.add_argument("--dataname", type=str, default='parking-garage.g2o', help="dataset name")
6061
parser.add_argument('--no-vectorize', dest='vectorize', action='store_false', help="to save memory")
6162
parser.add_argument('--vectorize', action='store_true', help='to accelerate computation')
62-
parser.set_defaults(vectorize=True)
63+
parser.set_defaults(vectorize=False)
6364
args = parser.parse_args(); print(args)
6465
os.makedirs(os.path.join(args.save), exist_ok=True)
6566

6667
data = G2OPGO(args.dataroot, args.dataname, device=args.device)
6768
edges, poses, infos = data.edges, data.poses, data.infos
6869

70+
######################################################################
71+
# Define Optimizer
72+
# -------------------------------------------------------------
73+
6974
graph = PoseGraph(data.nodes).to(args.device)
7075
solver = ppos.Cholesky()
7176
strategy = ppost.TrustRegion(radius=args.radius)
@@ -91,4 +96,5 @@ def plot_and_save(points, pngname, title='', axlim=None):
9196
######################################################################
9297
# The 2nd implementation: equivalent to the 1st one, but more compact
9398
# --------------------------------------------------------------------
99+
94100
scheduler.optimize(input=(edges, poses), weight=infos)

0 commit comments

Comments
 (0)