If the last sample of a batch is empty, from_dense() drops it completely.
This causes a silent size mismatch when going back to dense with to_dense().
B, C, H, W = 4, 1, 8, 8
x = torch.rand(B, C, H, W)
x[-1] = 0.0 # zero out the last sample
v = Voxels.from_dense(x)
out = v.to_dense(channel_dim=1, spatial_shape=(H, W))
print("input: ", x.shape)
print("coordinate_tensor: ", v.coordinate_tensor.shape)
print("feature_tensor: ", v.feature_tensor.shape)
print("offsets: ", v.offsets.shape)
print("output: ", out.shape)
output:
input: torch.Size([4, 1, 8, 8])
coordinate_tensor: torch.Size([192, 2])
feature_tensor: torch.Size([192, 1])
offsets: torch.Size([4]) # --> should have been 4+1
output: torch.Size([3, 1, 8, 8]) # --> should go back to 4