Skip to content

from_dense()\to_dense() batch size mismatch if last sample is empty #23

@mvicenzi

Description

@mvicenzi

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions