Skip to content

Commit

Permalink
datasets/nuscenes: fix timestamp rounding bug
Browse files Browse the repository at this point in the history
  • Loading branch information
d4l3k committed Sep 11, 2023
1 parent 1600b33 commit 44be0e2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
12 changes: 9 additions & 3 deletions torchdrive/datasets/nuscenes_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,7 @@ def _getitem(self, sample_data: SampleData) -> Dict[str, object]:

cam_T = rotation_mat.inverse().matmul(cam_T)

# timestamp is in microseconds, need to convert it to seconds
timestamp = sample_data["timestamp"] / 1e6
timestamp = sample_data["timestamp"]

# Get the image
img_path = os.path.join(self.dataroot, sample_data["filename"]) # current image
Expand Down Expand Up @@ -231,12 +230,19 @@ def __getitem__(self, idx: int) -> Dict[str, object]:

imgs = [fd["color"] for fd in frame_dicts]

# timestamp is in microseconds, need to convert it to seconds and
# normalize to first frame
frame_time = torch.tensor([fd["frame_time"] for fd in frame_dicts], dtype=torch.int64)
frame_time = frame_time - frame_time[0]
frame_time = frame_time.float()/1e6


return {
"weight": torch.tensor(frame_dicts[0]["weight"]),
"distance": torch.stack(dists),
"cam_T": torch.stack(cam_Ts),
"frame_T": torch.stack(frame_Ts),
"frame_time": torch.tensor([fd["frame_time"] for fd in frame_dicts]),
"frame_time": frame_time,
"K": frame_dicts[0][
"K"
], # only one cam to pixel matrix is required as it doesn't change during drive
Expand Down
6 changes: 4 additions & 2 deletions torchdrive/tasks/voxel.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,8 +683,10 @@ def _sfm_loss(
world_to_src_cam = batch.world_to_cam(cam, src_frame)
time = frame_time[:, src_frame]

if ctx.log_text:
ctx.add_scalar(f"frame_time_max/{offset}", time.abs().amax())
if ctx.log_text and offset != 0:
time_max = time.abs().amax()
assert time_max > 0 and time_max < 60, f"frame_time is bad {offset} {time}"
ctx.add_scalar(f"frame_time_max/{offset}", time_max)

src_color = batch.color[cam][:, src_frame]
src_color = F.interpolate(
Expand Down

0 comments on commit 44be0e2

Please sign in to comment.