Skip to content

Commit 1e9babb

Browse files
committed
fix mypy no-any-return errors in navit.py
Signed-off-by: Vikash Gupta <write2vikash@gmail.com>
1 parent aa7a76a commit 1e9babb

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

monai/networks/nets/navit.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
from collections.abc import Callable, Sequence
1515
from functools import partial
16+
from typing import cast
1617

1718
import torch
1819
import torch.nn as nn
@@ -96,7 +97,7 @@ def __init__(self, num_heads: int, dim_head: int) -> None:
9697
self.gamma = nn.Parameter(torch.ones(num_heads, 1, dim_head))
9798

9899
def forward(self, x: Tensor) -> Tensor:
99-
return F.normalize(x, dim=-1) * self.scale * self.gamma
100+
return cast(Tensor, F.normalize(x, dim=-1) * self.scale * self.gamma)
100101

101102

102103
class _NaViTAttention(nn.Module):
@@ -174,7 +175,7 @@ def forward(self, x: Tensor, context: Tensor | None = None, attn_mask: Tensor |
174175
attn = self.drop_weights(dots.softmax(dim=-1))
175176
out = torch.matmul(attn, v) # (B, heads, N, dim_head)
176177
out = out.transpose(1, 2).flatten(-2) # (B, N, inner_dim)
177-
return self.drop_output(self.out_proj(out))
178+
return cast(Tensor, self.drop_output(self.out_proj(out)))
178179

179180

180181
class _NaViTTransformerBlock(nn.Module):
@@ -571,4 +572,4 @@ def forward(
571572
is_valid = (image_id_range.unsqueeze(0) < num_images_t.unsqueeze(1)).reshape(-1) # (B * max_queries,)
572573
pooled = pooled[is_valid] # (total_images, hidden_size)
573574

574-
return self.mlp_head(pooled) # (total_images, num_classes)
575+
return cast(Tensor, self.mlp_head(pooled)) # (total_images, num_classes)

0 commit comments

Comments
 (0)