Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* add time

* fix black

---------

Co-authored-by: LcDog <[email protected]>
  • Loading branch information
lsongx and lsongx authored Feb 10, 2023
1 parent df784e9 commit b653eef
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
4 changes: 4 additions & 0 deletions nerfstudio/cameras/camera_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,16 @@ def get_spiral_path(
new_c2ws.append(c2wh[:3, :4])
new_c2ws = torch.stack(new_c2ws, dim=0)

times = None
if camera.times is not None:
times = torch.linspace(0, 1, steps)[:, None]
return Cameras(
fx=camera.fx[0],
fy=camera.fy[0],
cx=camera.cx[0],
cy=camera.cy[0],
camera_to_worlds=new_c2ws,
times=times,
)


Expand Down
4 changes: 2 additions & 2 deletions nerfstudio/cameras/cameras.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,15 +230,15 @@ def _init_get_height_width(
c_x_y: cx or cy for when h_w == None
"""
if isinstance(h_w, int):
h_w = torch.Tensor([h_w]).to(torch.int64).to(self.device)
h_w = torch.as_tensor([h_w]).to(torch.int64).to(self.device)
elif isinstance(h_w, torch.Tensor):
assert not torch.is_floating_point(h_w), f"height and width tensor must be of type int, not: {h_w.dtype}"
h_w = h_w.to(torch.int64).to(self.device)
if h_w.ndim == 0 or h_w.shape[-1] != 1:
h_w = h_w.unsqueeze(-1)
# assert torch.all(h_w == h_w.view(-1)[0]), "Batched cameras of different h, w will be allowed in the future."
elif h_w is None:
h_w = torch.Tensor((c_x_y * 2).to(torch.int64).to(self.device))
h_w = torch.as_tensor((c_x_y * 2)).to(torch.int64).to(self.device)
else:
raise ValueError("Height must be an int, tensor, or None, received: " + str(type(h_w)))
return h_w
Expand Down
3 changes: 1 addition & 2 deletions nerfstudio/field_components/temporal_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ def forward(
@staticmethod
@custom_bwd
def backward(ctx, grad):

inputs, temporal_row_index, embeddings, offsets, dy_dx = ctx.saved_tensors
B, D, grid_channel, C, L, S, H, gridtype = ctx.dims
align_corners = ctx.align_corners
Expand Down Expand Up @@ -336,7 +335,7 @@ def forward(self, xyz: TensorType["bs", "input_dim"], time: TensorType["bs", 1])
"""
outputs = TemporalGridEncodeFunc.apply(
xyz,
self.get_temporal_index(time[:, 0]),
self.get_temporal_index(time[:, 0].float()),
self.embeddings,
self.offsets,
self.per_level_scale,
Expand Down

0 comments on commit b653eef

Please sign in to comment.