-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy patheuler_lock_test.py
More file actions
82 lines (72 loc) · 2.88 KB
/
Copy patheuler_lock_test.py
File metadata and controls
82 lines (72 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
from mayavi import mlab
import numpy as np
import torch
from euler_lock_train import EulerRotPredict
from tqdm import tqdm
from util import *
from colors import *
from diffusion import GaussianDiffusion
BATCH = 64
if __name__ == "__main__":
device = torch.device(f"cuda") if torch.cuda.is_available() else torch.device("cpu")
net = EulerRotPredict().to(device)
net.load_state_dict(torch.load("weights/weights_euler_lock.pt", map_location=device))
net.eval()
process = GaussianDiffusion(net, loss_type="l2", image_size=None).to(device)
with torch.no_grad():
# Initial Haar-Uniform random rotations from QR decomp of normal IID matrix
R, _ = torch.qr(torch.randn((BATCH, 3, 3)))
euls = torch.stack(rmat_to_euler(R), dim=-1)
res = torch.zeros((process.num_timesteps, BATCH, 3))
for i in tqdm(reversed(range(0, process.num_timesteps)),
desc='sampling loop time step',
total=process.num_timesteps,
):
res[i] = euls.detach()
euls = process.p_sample(euls, torch.full((BATCH,), i, device=device, dtype=torch.long))
# Decompose into euler-angle form for plotting.
rmats = euler_to_rmat(*torch.unbind(res, -1))
endmats = rmats[0]
# Define sphere
count = 101
pi = np.pi
cos = torch.cos
sin = torch.sin
phi = torch.linspace(0, pi, count)
theta = torch.linspace(0, 2 * pi, count)
phi, theta = torch.meshgrid(phi, theta)
x = sin(phi) * cos(theta)
y = sin(phi) * sin(theta)
z = cos(phi)
points = torch.stack((x, y, z), dim=0)
axes = torch.eye(3)
mlab.figure(1, bgcolor=(1, 1, 1), fgcolor=(0, 0, 0), size=(800, 800))
mlab.clf()
obj = mlab.mesh(x.numpy(),
y.numpy(),
z.numpy(),
color=(0.9, 0.9, 0.9),
opacity=0.2,
transparent=True,
)
# Draw axes
mlab.plot3d([0, 1], [0, 0], [0, 0], color=GREY_F, tube_radius=None)
mlab.plot3d([0, 0], [0, 1], [0, 0], color=GREY_F, tube_radius=None)
mlab.plot3d([0, 0], [0, 0], [0, 1], color=GREY_F, tube_radius=None)
mlab.text3d(0.7, 0, 0, 'X', color=BLUE_F, scale=0.05)
mlab.text3d(0, 0.7, 0, 'Y', color=ORANGE_F, scale=0.05)
mlab.text3d(0, 0, 0.7, 'Z', color=GREEN_F, scale=0.05)
x_p, y_p, z_p = torch.unbind(endmats, dim=2)
opts = dict(resolution=20,transparent=True, opacity=1.0, scale_mode='none', scale_factor=0.07)
mlab.points3d(*x_p.T, color=BLUE_F, **opts)
mlab.points3d(*y_p.T, color=ORANGE_F, **opts)
mlab.points3d(*z_p.T, color=GREEN_F, **opts)
mlab.view(azimuth=60,
elevation=60,
distance=6.2,
focalpoint=(0.0, 0.0, 0.0),
)
mlab.gcf().scene.parallel_projection = True
mlab.gcf().scene.camera.parallel_scale = 1.0
mlab.show()
print('aaaa')