MCPcopy Index your code
hub / github.com/microsoft/TRELLIS / visualize_sample

Method visualize_sample

trellis/datasets/sparse_structure.py:51–106  ·  view source on GitHub ↗
(self, ss: Union[torch.Tensor, dict])

Source from the content-addressed store, hash-verified

49
50 @torch.no_grad()
51 def visualize_sample(self, ss: Union[torch.Tensor, dict]):
52 ss = ss if isinstance(ss, torch.Tensor) else ss['ss']
53
54 renderer = OctreeRenderer()
55 renderer.rendering_options.resolution = 512
56 renderer.rendering_options.near = 0.8
57 renderer.rendering_options.far = 1.6
58 renderer.rendering_options.bg_color = (0, 0, 0)
59 renderer.rendering_options.ssaa = 4
60 renderer.pipe.primitive = 'voxel'
61
62 # Build camera
63 yaws = [0, np.pi / 2, np.pi, 3 * np.pi / 2]
64 yaws_offset = np.random.uniform(-np.pi / 4, np.pi / 4)
65 yaws = [y + yaws_offset for y in yaws]
66 pitch = [np.random.uniform(-np.pi / 4, np.pi / 4) for _ in range(4)]
67
68 exts = []
69 ints = []
70 for yaw, pitch in zip(yaws, pitch):
71 orig = torch.tensor([
72 np.sin(yaw) * np.cos(pitch),
73 np.cos(yaw) * np.cos(pitch),
74 np.sin(pitch),
75 ]).float().cuda() * 2
76 fov = torch.deg2rad(torch.tensor(30)).cuda()
77 extrinsics = utils3d.torch.extrinsics_look_at(orig, torch.tensor([0, 0, 0]).float().cuda(), torch.tensor([0, 0, 1]).float().cuda())
78 intrinsics = utils3d.torch.intrinsics_from_fov_xy(fov, fov)
79 exts.append(extrinsics)
80 ints.append(intrinsics)
81
82 images = []
83
84 # Build each representation
85 ss = ss.cuda()
86 for i in range(ss.shape[0]):
87 representation = Octree(
88 depth=10,
89 aabb=[-0.5, -0.5, -0.5, 1, 1, 1],
90 device='cuda',
91 primitive='voxel',
92 sh_degree=0,
93 primitive_config={'solid': True},
94 )
95 coords = torch.nonzero(ss[i, 0], as_tuple=False)
96 representation.position = coords.float() / self.resolution
97 representation.depth = torch.full((representation.position.shape[0], 1), int(np.log2(self.resolution)), dtype=torch.uint8, device='cuda')
98
99 image = torch.zeros(3, 1024, 1024).cuda()
100 tile = [2, 2]
101 for j, (ext, intr) in enumerate(zip(exts, ints)):
102 res = renderer.render(representation, ext, intr, colors_overwrite=representation.position)
103 image[:, 512 * (j // tile[1]):512 * (j // tile[1] + 1), 512 * (j % tile[1]):512 * (j % tile[1] + 1)] = res['color']
104 images.append(image)
105
106 return torch.stack(images)
107

Callers

nothing calls this directly

Calls 5

renderMethod · 0.95
OctreeRendererClass · 0.85
floatMethod · 0.80
fullMethod · 0.80
cudaMethod · 0.45

Tested by

no test coverage detected