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: make two-stage extractor work with empty batches #56

Merged
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
3 changes: 2 additions & 1 deletion rul_adapt/model/two_stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def forward(self, inputs: torch.Tensor) -> torch.Tensor:
batch_size, upper_seq_len, input_channels, lower_seq_len = inputs.shape
inputs = inputs.reshape(-1, input_channels, lower_seq_len)
inputs = self.lower_stage(inputs)
inputs = inputs.reshape(batch_size, upper_seq_len, -1)
_, lower_output_units = inputs.shape
inputs = inputs.reshape(batch_size, upper_seq_len, lower_output_units)
inputs = torch.transpose(inputs, 1, 2)
inputs = self.upper_stage(inputs)

Expand Down
4 changes: 4 additions & 0 deletions tests/test_model/test_two_stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@ def test_forward_upper_lower_interaction(inputs, extractor):
outputs = extractor(inputs)

assert torch.allclose(upper_outputs, outputs[3])


def test_forward_with_empty_input(extractor):
output = extractor(torch.empty(0, 4, 3, 64))
Loading