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

[CI/code quality] Add clear github runner caches job + mypy fixes #1783

Merged
merged 9 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
mypy fixes
  • Loading branch information
felixdittrich92 committed Nov 19, 2024
commit 7b4ad9b53c1c8fbf1abe1fb9934582c97dde8888
4 changes: 2 additions & 2 deletions doctr/models/modules/transformer/pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ 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.matmul(query, key.transpose(-2, -1)) / math.sqrt(query.size(-1)) # type: ignore[assignment]
scores = torch.matmul(query, key.transpose(-2, -1)) / math.sqrt(query.size(-1))
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"))
scores = scores.masked_fill(mask == 0, float("-inf")) # type: ignore[attr-defined]
p_attn = torch.softmax(scores, dim=-1)
return torch.matmul(p_attn, value), p_attn

Expand Down
6 changes: 3 additions & 3 deletions doctr/transforms/functional/pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ 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 = min_val + (1 - min_val) * torch.rand(shift_shape) # type: ignore[assignment]
rgb_shift = min_val + (1 - min_val) * torch.rand(shift_shape)
# Inverse the color
if out.dtype == torch.uint8:
out = (out.to(dtype=rgb_shift.dtype) * rgb_shift).to(dtype=torch.uint8)
out = (out.to(dtype=rgb_shift.dtype) * rgb_shift).to(dtype=torch.uint8) # type: ignore[attr-defined]
else:
out = out * rgb_shift.to(dtype=out.dtype)
out = out * rgb_shift.to(dtype=out.dtype) # type: ignore[attr-defined]
# Inverse the color
out = 255 - out if out.dtype == torch.uint8 else 1 - out
return out
Expand Down
Loading