Fixed the problem where you couldn't run study inference on single video studies. #14
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When running the demo with a study that contains only one DICOM/MP4, encode_study crashes with:
RuntimeError: Tensors must have same number of dimensions: got 2 and 1
This PR makes get_views (in the model.py file) always return a 2-D tensor of shape (N, 11), even when N=1, so concatenation with the video features (N, 512) works for any batch size.
get_views previously did:
stack_of_view_encodings = torch.stack([torch.nn.functional.one_hot(out_views,11)]).squeeze().to(self.device)
When N=1, (1, 1, 11) becomes (11,) (rank-1), which cannot be concatenated with (1, 512) along dim=1.
What’s changed:
Replaced the above with a shape-safe line that preserves the batch dimension and matches dtype/device:
stack_of_view_encodings = torch.nn.functional.one_hot(out_views, num_classes=11).float().to(self.device) # (N, 11)
Expected behavior after this change:
The same code runs without error.
Shapes:
Backwards compatibility: