Skip to content

Make verbose flag work through API on both mesh pipeline and postprocessing #66

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions trellis/pipelines/trellis_image_to_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def sample_sparse_structure(
cond: dict,
num_samples: int = 1,
sampler_params: dict = {},
verbose: bool = True,
) -> torch.Tensor:
"""
Sample sparse structures with the given conditioning.
Expand All @@ -185,7 +186,7 @@ def sample_sparse_structure(
noise,
**cond,
**sampler_params,
verbose=True
verbose=verbose
).samples

# Decode occupancy latent
Expand Down Expand Up @@ -223,6 +224,7 @@ def sample_slat(
cond: dict,
coords: torch.Tensor,
sampler_params: dict = {},
verbose: bool = True,
) -> sp.SparseTensor:
"""
Sample structured latent with the given conditioning.
Expand All @@ -244,7 +246,7 @@ def sample_slat(
noise,
**cond,
**sampler_params,
verbose=True
verbose=verbose
).samples

std = torch.tensor(self.slat_normalization['std'])[None].to(slat.device)
Expand All @@ -263,6 +265,7 @@ def run(
slat_sampler_params: dict = {},
formats: List[str] = ['mesh', 'gaussian', 'radiance_field'],
preprocess_image: bool = True,
verbose: bool = True,
) -> dict:
"""
Run the pipeline.
Expand All @@ -278,6 +281,6 @@ def run(
image = self.preprocess_image(image)
cond = self.get_cond([image])
torch.manual_seed(seed)
coords = self.sample_sparse_structure(cond, num_samples, sparse_structure_sampler_params)
slat = self.sample_slat(cond, coords, slat_sampler_params)
coords = self.sample_sparse_structure(cond, num_samples, sparse_structure_sampler_params, verbose)
slat = self.sample_slat(cond, coords, slat_sampler_params, verbose)
return self.decode_slat(slat, formats)
4 changes: 2 additions & 2 deletions trellis/utils/postprocessing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def _fill_holes(
if verbose:
tqdm.write(f'Removed 0 faces by mincut')

mesh = _meshfix.PyTMesh()
mesh = _meshfix.PyTMesh(verbose=verbose)
mesh.load_array(verts.cpu().numpy(), faces.cpu().numpy())
mesh.fill_small_boundaries(nbe=max_hole_nbe, refine=True)
verts, faces = mesh.return_arrays()
Expand Down Expand Up @@ -439,7 +439,7 @@ def to_glb(
vertices, faces, uvs = parametrize_mesh(vertices, faces)

# bake texture
observations, extrinsics, intrinsics = render_multiview(app_rep, resolution=1024, nviews=100)
observations, extrinsics, intrinsics = render_multiview(app_rep, resolution=1024, nviews=100, verbose=verbose)
masks = [np.any(observation > 0, axis=-1) for observation in observations]
extrinsics = [extrinsics[i].cpu().numpy() for i in range(len(extrinsics))]
intrinsics = [intrinsics[i].cpu().numpy() for i in range(len(intrinsics))]
Expand Down
4 changes: 2 additions & 2 deletions trellis/utils/render_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ def render_video(sample, resolution=512, bg_color=(0, 0, 0), num_frames=300, r=2
return render_frames(sample, extrinsics, intrinsics, {'resolution': resolution, 'bg_color': bg_color}, **kwargs)


def render_multiview(sample, resolution=512, nviews=30):
def render_multiview(sample, resolution=512, nviews=30, **kwargs):
r = 2
fov = 40
cams = [sphere_hammersley_sequence(i, nviews) for i in range(nviews)]
yaws = [cam[0] for cam in cams]
pitchs = [cam[1] for cam in cams]
extrinsics, intrinsics = yaw_pitch_r_fov_to_extrinsics_intrinsics(yaws, pitchs, r, fov)
res = render_frames(sample, extrinsics, intrinsics, {'resolution': resolution, 'bg_color': (0, 0, 0)})
res = render_frames(sample, extrinsics, intrinsics, {'resolution': resolution, 'bg_color': (0, 0, 0)}, **kwargs)
return res['color'], extrinsics, intrinsics


Expand Down