Skip to content
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

Fix edge case batch_size=1 and implement related test. #30

Merged
merged 1 commit into from
Jul 7, 2022
Merged
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
2 changes: 1 addition & 1 deletion myria3d/models/modules/randla_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ def knn_compact(
)

# Get back to compact shape
batch_size_y = len(pos_y[1])
batch_size_y = pos_y.size(1)
compact_shape_y = (num_graphs, batch_size_y, -1)
x_idx = x_idx_long.view(compact_shape_y)
y_idx = y_idx_long.view(compact_shape_y)
Expand Down
13 changes: 10 additions & 3 deletions tests/myria3d/models/modules/test_randla_net.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import pytest
import torch
from torch_geometric.data import Batch
from myria3d.models.modules.randla_net import RandLANet


def test_fake_run_randlanet():
"""Documents expected data format and make a forward pass with RandLa-Net"""
@pytest.mark.parametrize("num_graphs", [1, 4])
def test_fake_run_randlanet(num_graphs):
"""Documents expected data format and make a forward pass with RandLa-Net

Model pass with "batch_size=1" is a edge case that needs to pass to avoid unexpected crash due to incomplete batch at the
end of an inference.

"""
num_euclidian_dimensions = 3
num_features = 9
d_in = num_euclidian_dimensions + num_features
Expand All @@ -17,7 +24,7 @@ def test_fake_run_randlanet():
"num_classes": num_classes,
}
batch = Batch()
batch.num_graphs = 4
batch.num_graphs = 1
num_points = 12500
batch.pos = torch.rand((num_points * batch.num_graphs, num_euclidian_dimensions))
batch.x = torch.rand((num_points * batch.num_graphs, num_features))
Expand Down