kaifz commited on
Commit
18bc2d6
·
1 Parent(s): 12cbc75

add arrows

Browse files
app.py CHANGED
@@ -9,15 +9,6 @@ import random
9
  import math
10
  import hydra
11
  import numpy as np
12
-
13
- # import importlib
14
- # import torch
15
- # import torch.nn as nn
16
- # print(torch.__version__)
17
- # print(torch.version.cuda)
18
- # import torch.backends.cudnn
19
- # from torch.utils.data import DataLoader
20
-
21
  import glob
22
  import os
23
  import subprocess
@@ -32,69 +23,22 @@ import spaces
32
  from spaces import zero
33
  zero.startup()
34
 
35
- # def install_cuda_toolkit():
36
- # # CUDA_TOOLKIT_URL = "https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda_11.8.0_520.61.05_linux.run"
37
- # # CUDA_TOOLKIT_URL = "https://developer.download.nvidia.com/compute/cuda/12.2.0/local_installers/cuda_12.2.0_535.54.03_linux.run"
38
- # CUDA_TOOLKIT_URL = "https://developer.download.nvidia.com/compute/cuda/12.4.0/local_installers/cuda_12.4.0_550.54.14_linux.run"
39
- # CUDA_TOOLKIT_FILE = "/tmp/%s" % os.path.basename(CUDA_TOOLKIT_URL)
40
- # subprocess.call(["wget", "-q", CUDA_TOOLKIT_URL, "-O", CUDA_TOOLKIT_FILE])
41
- # subprocess.call(["chmod", "+x", CUDA_TOOLKIT_FILE])
42
- # subprocess.call([CUDA_TOOLKIT_FILE, "--silent", "--toolkit"])
43
-
44
- # os.environ["CUDA_HOME"] = "/usr/local/cuda"
45
- # os.environ["PATH"] = "%s/bin:%s" % (os.environ["CUDA_HOME"], os.environ["PATH"])
46
- # os.environ["LD_LIBRARY_PATH"] = "%s/lib:%s" % (
47
- # os.environ["CUDA_HOME"],
48
- # "" if "LD_LIBRARY_PATH" not in os.environ else os.environ["LD_LIBRARY_PATH"],
49
- # )
50
- # # Fix: arch_list[-1] += '+PTX'; IndexError: list index out of range
51
- # os.environ["TORCH_CUDA_ARCH_LIST"] = "8.0;8.6"
52
-
53
- # install_cuda_toolkit()
54
-
55
- # gs_path = Path(__file__).parent / "src/third-party/diff-gaussian-rasterization-w-depth"
56
- # subprocess.check_call([sys.executable, "-m", "pip", "install", "-e", str(gs_path)])
57
- # site.main() # re-processes every *.pth in site-packages
58
- # importlib.invalidate_caches()
59
- # diff_gaussian_rasterization = importlib.import_module("diff_gaussian_rasterization")
60
-
61
- # subprocess.check_call([sys.executable, "-m", "pip", "install", "--no-deps", "dgl", "-f", "https://data.dgl.ai/wheels/torch-2.4/cu124/repo.html"])
62
-
63
- # subprocess.check_call([sys.executable, "-m", "pip", "uninstall", "-y", "torch", "torchvision", "torchaudio"])
64
- # subprocess.check_call([sys.executable, "-m", "pip", "install", "torch==2.4.0", "torchvision==0.19.0", "torchaudio==2.4.0", "--index-url", "https://download.pytorch.org/whl/cu124"])
65
- # os.system('conda install conda-forge::ffmpeg')
66
-
67
- # site.main() # re-processes every *.pth in site-packages
68
- # importlib.invalidate_caches()
69
- # torch = importlib.import_module("torch")
70
-
71
  import torch
72
  import torch.nn as nn
73
  from torch.utils.data import DataLoader
74
  import kornia
75
- # import warp as wp
76
 
77
  from diff_gaussian_rasterization import GaussianRasterizer
78
  from diff_gaussian_rasterization import GaussianRasterizationSettings as Camera
79
 
80
- # print(torch.__version__)
81
- # print(torch.version.cuda)
82
-
83
  import sys
84
  sys.path.insert(0, str(Path(__file__).parent / "src"))
85
  sys.path.append(str(Path(__file__).parent / "src" / "experiments"))
86
 
87
- # from pgnd.sim import Friction, CacheDiffSimWithFrictionBatch, StaticsBatch, CollidersBatch
88
- # from pgnd.material import PGNDModel
89
- # from pgnd.utils import Logger, get_root, mkdir
90
-
91
  from real_world.utils.render_utils import interpolate_motions
92
  from real_world.gs.helpers import setup_camera
93
  from real_world.gs.convert import save_to_splat, read_splat
94
 
95
- # from diff_gaussian_rasterization import GaussianRasterizer
96
- # from diff_gaussian_rasterization import GaussianRasterizationSettings as Camera
97
-
98
  root = Path(__file__).parent / "src" / "experiments"
99
 
100
  def make_video(
@@ -172,6 +116,7 @@ class DynamicsVisualizer:
172
  self.k_wgt = 16 # knn for weights
173
  self.with_bg = True
174
  self.render_gripper = True
 
175
  self.verbose = False
176
 
177
  self.dt_base = cfg.sim.dt
@@ -840,6 +785,65 @@ class DynamicsVisualizer:
840
  opa = torch.cat([opa, g_opacities], dim=0)
841
  scales = torch.cat([scales, g_scales], dim=0)
842
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
843
  # normalize
844
  quat = torch.nn.functional.normalize(quat, dim=-1)
845
 
@@ -944,6 +948,7 @@ class DynamicsVisualizer:
944
  num_particles = self.cfg.sim.n_particles
945
  self.load_scaniverse(in_dir)
946
  self.init_model(batch_size, num_steps, num_particles, ckpt_path=None)
 
947
 
948
  params = self.preprocess_gs(self.params)
949
  if self.with_bg:
@@ -1079,6 +1084,7 @@ class DynamicsVisualizer:
1079
  batch_size = 1
1080
  num_particles = self.cfg.sim.n_particles
1081
  self.init_model(batch_size, num_steps, num_particles, ckpt_path=None)
 
1082
 
1083
  # im_list = []
1084
  for i in range(num_steps):
@@ -1090,6 +1096,8 @@ class DynamicsVisualizer:
1090
  if self.verbose:
1091
  print('command:', command.cpu().numpy().tolist())
1092
 
 
 
1093
  assert self.state['sub_pos'] is None
1094
 
1095
  if self.state['sub_pos'] is None:
 
9
  import math
10
  import hydra
11
  import numpy as np
 
 
 
 
 
 
 
 
 
12
  import glob
13
  import os
14
  import subprocess
 
23
  from spaces import zero
24
  zero.startup()
25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  import torch
27
  import torch.nn as nn
28
  from torch.utils.data import DataLoader
29
  import kornia
 
30
 
31
  from diff_gaussian_rasterization import GaussianRasterizer
32
  from diff_gaussian_rasterization import GaussianRasterizationSettings as Camera
33
 
 
 
 
34
  import sys
35
  sys.path.insert(0, str(Path(__file__).parent / "src"))
36
  sys.path.append(str(Path(__file__).parent / "src" / "experiments"))
37
 
 
 
 
 
38
  from real_world.utils.render_utils import interpolate_motions
39
  from real_world.gs.helpers import setup_camera
40
  from real_world.gs.convert import save_to_splat, read_splat
41
 
 
 
 
42
  root = Path(__file__).parent / "src" / "experiments"
43
 
44
  def make_video(
 
116
  self.k_wgt = 16 # knn for weights
117
  self.with_bg = True
118
  self.render_gripper = True
119
+ self.render_direction = True
120
  self.verbose = False
121
 
122
  self.dt_base = cfg.sim.dt
 
785
  opa = torch.cat([opa, g_opacities], dim=0)
786
  scales = torch.cat([scales, g_scales], dim=0)
787
 
788
+ if self.render_direction:
789
+ gripper_direction = self.gripper_direction
790
+ gripper_direction = gripper_direction / (torch.norm(gripper_direction, dim=-1, keepdim=True) + 1e-10) # normalize
791
+
792
+ R = self.preprocess_metadata['R']
793
+ # model frame to data frame
794
+ direction = gripper_direction @ R.T
795
+
796
+ n_grippers = 1
797
+ N = 200
798
+ length = 0.2
799
+ kk = 5
800
+ xyz_test = torch.zeros((n_grippers, N + N // kk + N // kk, 3), device=self.torch_device, dtype=xyz.dtype)
801
+
802
+ gripper_now_inv_xyz = self.inverse_preprocess_gripper(self.state['prev_key_pos'][None].clone())
803
+ gripper_now_inv_rot = torch.eye(3, device=self.torch_device).unsqueeze(0).repeat(n_grippers, 1, 1)
804
+
805
+ center_point = torch.tensor([0.0, 0.0, 0.10], device=self.torch_device, dtype=xyz.dtype).reshape(1, 3) # center point in gripper frame
806
+ gripper_center_inv_xyz = gripper_now_inv_xyz + \
807
+ torch.einsum('ijk,ik->ij', gripper_now_inv_rot, center_point) # (n_grippers, 3)
808
+
809
+ for i in range(N):
810
+ offset = i / N * length * direction
811
+ xyz_test[:, i] = gripper_center_inv_xyz + offset
812
+
813
+ if direction[0, 2] < 0.9 and direction[0, 2] > -0.9: # not vertical
814
+ direction_up = -direction + torch.tensor([0.0, 0.0, 0.5], device=self.torch_device, dtype=xyz.dtype)
815
+ direction_up = direction_up / (torch.norm(direction_up, dim=-1, keepdim=True) + 1e-10) # normalize
816
+ direction_down = -direction + torch.tensor([0.0, 0.0, -0.5], device=self.torch_device, dtype=xyz.dtype)
817
+ direction_down = direction_down / (torch.norm(direction_down, dim=-1, keepdim=True) + 1e-10) # normalize
818
+ else:
819
+ direction_up = -direction + torch.tensor([0.0, 0.5, 0.0], device=self.torch_device, dtype=xyz.dtype)
820
+ direction_up = direction_up / (torch.norm(direction_up, dim=-1, keepdim=True) + 1e-10) # normalize
821
+ direction_down = -direction + torch.tensor([0.0, -0.5, 0.0], device=self.torch_device, dtype=xyz.dtype)
822
+ direction_down = direction_down / (torch.norm(direction_down, dim=-1, keepdim=True) + 1e-10) # normalize
823
+
824
+ for i in range(N, N + N // kk):
825
+ offset = length * direction + (i - N) / N * length * direction_up
826
+ xyz_test[:, i] = gripper_center_inv_xyz + offset
827
+
828
+ for i in range(N + N // kk, N + N // kk + N // kk):
829
+ offset = length * direction + (i - N - N // kk) / N * length * direction_down
830
+ xyz_test[:, i] = gripper_center_inv_xyz + offset
831
+
832
+ color_test = torch.zeros_like(xyz_test, device=self.torch_device, dtype=xyz.dtype)
833
+ color_test[:, :, 0] = 255 / 255 # red
834
+ color_test[:, :, 1] = 80 / 255 # green
835
+ color_test[:, :, 2] = 110 / 255 # blue
836
+ quat_test = torch.zeros((n_grippers, N + N // kk + N // kk, 4), device=self.torch_device, dtype=xyz.dtype)
837
+ quat_test[:, :, 0] = 1.0 # identity quaternion
838
+ opa_test = torch.ones((n_grippers, N + N // kk + N // kk, 1), device=self.torch_device, dtype=xyz.dtype)
839
+ scales_test = torch.ones((n_grippers, N + N // kk + N // kk, 3), device=self.torch_device, dtype=xyz.dtype) * 0.002
840
+
841
+ xyz = torch.cat([xyz, xyz_test.reshape(-1, 3)], dim=0)
842
+ rgb = torch.cat([rgb, color_test.reshape(-1, 3)], dim=0)
843
+ quat = torch.cat([quat, quat_test.reshape(-1, 4)], dim=0)
844
+ opa = torch.cat([opa, opa_test.reshape(-1, 1)], dim=0)
845
+ scales = torch.cat([scales, scales_test.reshape(-1, 3)], dim=0)
846
+
847
  # normalize
848
  quat = torch.nn.functional.normalize(quat, dim=-1)
849
 
 
948
  num_particles = self.cfg.sim.n_particles
949
  self.load_scaniverse(in_dir)
950
  self.init_model(batch_size, num_steps, num_particles, ckpt_path=None)
951
+ self.render_direction = False
952
 
953
  params = self.preprocess_gs(self.params)
954
  if self.with_bg:
 
1084
  batch_size = 1
1085
  num_particles = self.cfg.sim.n_particles
1086
  self.init_model(batch_size, num_steps, num_particles, ckpt_path=None)
1087
+ self.render_direction = True
1088
 
1089
  # im_list = []
1090
  for i in range(num_steps):
 
1096
  if self.verbose:
1097
  print('command:', command.cpu().numpy().tolist())
1098
 
1099
+ self.gripper_direction = command.clone()
1100
+
1101
  assert self.state['sub_pos'] is None
1102
 
1103
  if self.state['sub_pos'] is None:
src/experiments/log/gs/temp/form_video.mp4 CHANGED
Binary files a/src/experiments/log/gs/temp/form_video.mp4 and b/src/experiments/log/gs/temp/form_video.mp4 differ
 
src/experiments/log/gs/temp/gs_pred.splat CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:111f09eae16a77a8e63af83f4adcb78c21ac301113a18fae10bcaa89432aff5f
3
- size 7675392
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:753a59d8cb6fb82e29d233db6865e6c6a87fabc5b469619e4310d3fbee619f6c
3
+ size 7684352
src/experiments/log/temp/0000.png CHANGED

Git LFS Details

  • SHA256: 77b3cfbc740682e220917dbc11f617077f5f1b7f3897565aa233ae20961b4e63
  • Pointer size: 131 Bytes
  • Size of remote file: 290 kB

Git LFS Details

  • SHA256: 3dfd0c59aa71264b19a4124173880ea030768039594554b21eaeaa5c4264d0b2
  • Pointer size: 131 Bytes
  • Size of remote file: 294 kB
src/experiments/log/temp/0001.png CHANGED

Git LFS Details

  • SHA256: cd667b7ce224a604ce20103753e79faa3d94deb1ac01d3ac2530c78df454430f
  • Pointer size: 131 Bytes
  • Size of remote file: 290 kB

Git LFS Details

  • SHA256: ea86d373cc91a288fa3fd16b672135a539864a78bdaeff7cd97557f33b38ae25
  • Pointer size: 131 Bytes
  • Size of remote file: 294 kB
src/experiments/log/temp/0002.png CHANGED

Git LFS Details

  • SHA256: 7d97b92f82aa2a4c2ab2ecdbafb27265f2b8246c41ae48906a2694f1baa234b5
  • Pointer size: 131 Bytes
  • Size of remote file: 290 kB

Git LFS Details

  • SHA256: 00b31a90f8faa0ee5ba954e603fe6fbfcb2d2c92ba2e67ac741b41b38aa19510
  • Pointer size: 131 Bytes
  • Size of remote file: 294 kB
src/experiments/log/temp/0003.png CHANGED

Git LFS Details

  • SHA256: a53ec2eb51510a425e94d6c77cfffe523b3d7b58d3f55f9c9971bb0860df14ba
  • Pointer size: 131 Bytes
  • Size of remote file: 290 kB

Git LFS Details

  • SHA256: 31fa97cfdb89e970548d6828ff615cc5e4a42b1f4115cf87ef2fec9cec9c9074
  • Pointer size: 131 Bytes
  • Size of remote file: 293 kB
src/experiments/log/temp/0004.png CHANGED

Git LFS Details

  • SHA256: 0cc56f75c675a58ec61e482d5e9cf532e7880b33f9ed43248c75e62134aa897d
  • Pointer size: 131 Bytes
  • Size of remote file: 290 kB

Git LFS Details

  • SHA256: 550b4d0abf1702dab6f1bac736643638d3e0e8e32dbb8f3fa0165dafdf10252e
  • Pointer size: 131 Bytes
  • Size of remote file: 293 kB
src/experiments/log/temp/0005.png CHANGED

Git LFS Details

  • SHA256: 25eb614538d6665089a9abf3acd61117645ecf8087e96aaf89cd9a0236f222bc
  • Pointer size: 131 Bytes
  • Size of remote file: 289 kB

Git LFS Details

  • SHA256: b06780e0198f3e4186ea4a487eb1c9ed80765b4db9167ceb636247a5e2a3fd90
  • Pointer size: 131 Bytes
  • Size of remote file: 293 kB
src/experiments/log/temp/0006.png CHANGED

Git LFS Details

  • SHA256: 4f138c4c08e933e41e4545fd75d3b400fbe8c5f51cab29b6113c09d43fdc6a8f
  • Pointer size: 131 Bytes
  • Size of remote file: 289 kB

Git LFS Details

  • SHA256: 35c96f984bc0f5343aa8cca6450c0c832871eb2af03d39764463791f11615759
  • Pointer size: 131 Bytes
  • Size of remote file: 293 kB
src/experiments/log/temp/0007.png CHANGED

Git LFS Details

  • SHA256: 39e47213f688d7e8322c52cdcb90515ee2f3b948f4bcaa310a010892aba12bd8
  • Pointer size: 131 Bytes
  • Size of remote file: 289 kB

Git LFS Details

  • SHA256: 27093820fe6c46d48fb4780a39e862d45c8b6c424b4f3a51a4ede6cb7f9019c1
  • Pointer size: 131 Bytes
  • Size of remote file: 292 kB
src/experiments/log/temp/0008.png CHANGED

Git LFS Details

  • SHA256: 8574795142c6738e04e34467f5fe6f42fc6132b681483608bebc8ed814eebba0
  • Pointer size: 131 Bytes
  • Size of remote file: 289 kB

Git LFS Details

  • SHA256: 92b8b876cf511e7806c8f15f336599c0131e98b913e20682353d44d21238e633
  • Pointer size: 131 Bytes
  • Size of remote file: 292 kB
src/experiments/log/temp/0009.png CHANGED

Git LFS Details

  • SHA256: e3dbe50211cfa3b861b3ae4d1695cfda3a886f4f710870e6134d7ff7d0beb990
  • Pointer size: 131 Bytes
  • Size of remote file: 289 kB

Git LFS Details

  • SHA256: 238f779aa6aaea8ced58124ea9b9a05f95a455d564c05a09d1d5b8e87a143273
  • Pointer size: 131 Bytes
  • Size of remote file: 292 kB
src/experiments/log/temp/0010.png CHANGED

Git LFS Details

  • SHA256: 37dbc2cb4ebdb788971f1676d3f86c0d51ea8b058fa709bbec16347a20e593f5
  • Pointer size: 131 Bytes
  • Size of remote file: 289 kB

Git LFS Details

  • SHA256: 233e20259659e1934c205eb2fdea079cfa77402deb55183b728982bf4284240e
  • Pointer size: 131 Bytes
  • Size of remote file: 291 kB
src/experiments/log/temp/0011.png CHANGED

Git LFS Details

  • SHA256: 111c751c5c68bc9f5343c3ccbd87ac0549fcedec5246dc47a985ed1f777afb99
  • Pointer size: 131 Bytes
  • Size of remote file: 289 kB

Git LFS Details

  • SHA256: 9b5c3dc6ae991e27e02ba8b8d06d5cfae06b9f62588f18fedaaacbf38a1cc8ba
  • Pointer size: 131 Bytes
  • Size of remote file: 291 kB
src/experiments/log/temp/0012.png CHANGED

Git LFS Details

  • SHA256: 0f412dfad710635fd79c080705b470155a738eb7b143fe739bc6303be1ab57db
  • Pointer size: 131 Bytes
  • Size of remote file: 289 kB

Git LFS Details

  • SHA256: 022b5a63cd387b55a8639430270e54378562d0212d7bd8cd847251feeea62c03
  • Pointer size: 131 Bytes
  • Size of remote file: 291 kB
src/experiments/log/temp/0013.png CHANGED

Git LFS Details

  • SHA256: 7b5ee00ff589b68b25ed014038a08a28d5214ca328ea53705b63c7a5d74093dd
  • Pointer size: 131 Bytes
  • Size of remote file: 289 kB

Git LFS Details

  • SHA256: 52cb92825263f5314ee9a983e9d60af223187c3f110e01cacb10274d704d0e2d
  • Pointer size: 131 Bytes
  • Size of remote file: 290 kB
src/experiments/log/temp/0014.png CHANGED

Git LFS Details

  • SHA256: f40c996ebbd4ef62355d3e6bfe4c97ba07d1184d06b108444658fb367e55cdff
  • Pointer size: 131 Bytes
  • Size of remote file: 289 kB

Git LFS Details

  • SHA256: 104884ddd7435ff788d2ecd7b28cbb6702bafa2765abc9c4f28e2d0301f39276
  • Pointer size: 131 Bytes
  • Size of remote file: 290 kB