Skip to content

Commit

Permalink
Add support for single timestep query shape
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobbieker committed Sep 28, 2021
1 parent 818c8c5 commit f0909b2
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions perceiver_pytorch/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ def __init__(
sine_only=sine_only,
)
self.channel_dim = channel_dim
if conv_layer == "3d":
if (
conv_layer == "3d" and len(self.query_shape) == 3
): # If Query shape is for an image, then 3D conv won't work
conv = torch.nn.Conv3d
elif conv_layer == "2d":
conv = torch.nn.Conv2d
Expand Down Expand Up @@ -89,7 +91,7 @@ def forward(self, x: torch.Tensor) -> torch.Tensor:
z = torch.squeeze(z, dim=-1) # Extra 1 for some reason
_LOG.debug(f"Z: {z.shape}")
# Do 3D or 2D CNN to keep same spatial size, concat, then linearize
if self.conv_layer == "2d":
if self.conv_layer == "2d" and len(self.query_shape) == 3:
# Iterate through time dimension
outs = []
for i in range(x.shape[1]):
Expand Down

0 comments on commit f0909b2

Please sign in to comment.