Skip to content

Commit

Permalink
mypy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
felixdittrich92 committed Nov 18, 2024
1 parent ad59720 commit 7ad6057
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion doctr/models/modules/transformer/pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def scaled_dot_product_attention(
query: torch.Tensor, key: torch.Tensor, value: torch.Tensor, mask: Optional[torch.Tensor] = None
) -> Tuple[torch.Tensor, torch.Tensor]:
"""Scaled Dot-Product Attention"""
scores: torch.Tensor = torch.matmul(query, key.transpose(-2, -1)) / math.sqrt(query.size(-1))
scores = torch.matmul(query, key.transpose(-2, -1)) / math.sqrt(query.size(-1)) # type: ignore[assignment]
if mask is not None:
# NOTE: to ensure the ONNX compatibility, masked_fill works only with int equal condition
scores = scores.masked_fill(mask == 0, float("-inf"))
Expand Down
2 changes: 1 addition & 1 deletion doctr/transforms/functional/pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def invert_colors(img: torch.Tensor, min_val: float = 0.6) -> torch.Tensor:
out = F.rgb_to_grayscale(img, num_output_channels=3)
# Random RGB shift
shift_shape = [img.shape[0], 3, 1, 1] if img.ndim == 4 else [3, 1, 1]
rgb_shift: torch.Tensor = min_val + (1 - min_val) * torch.rand(shift_shape)
rgb_shift = min_val + (1 - min_val) * torch.rand(shift_shape) # type: ignore[assignment]
# Inverse the color
if out.dtype == torch.uint8:
out = (out.to(dtype=rgb_shift.dtype) * rgb_shift).to(dtype=torch.uint8)
Expand Down
4 changes: 2 additions & 2 deletions doctr/transforms/modules/pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ def __call__(self, x: torch.Tensor) -> torch.Tensor:
# Reshape the distribution
try:
if x.dtype == torch.uint8:
return ( # type: ignore[attr-defined]
(
return (
( # type: ignore[attr-defined]
255
* random_shadow(
x.to(dtype=torch.float32) / 255,
Expand Down

0 comments on commit 7ad6057

Please sign in to comment.