Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 9 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ jobs:
type-check:
runs-on: ubuntu-latest
needs: lint
strategy:
fail-fast: false
matrix:
target:
- landmarkdiff/
- scripts/
- benchmarks/
steps:
- uses: actions/checkout@v5
- uses: actions/setup-python@v6
Expand All @@ -37,8 +44,8 @@ jobs:
cache: pip
- name: Install dependencies
run: pip install -e ".[dev]"
- name: Type check
run: mypy landmarkdiff/ --ignore-missing-imports
- name: Type check ${{ matrix.target }}
run: mypy ${{ matrix.target }}
pre-commit:
runs-on: ubuntu-latest
needs: lint
Expand Down
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ repos:
additional_dependencies: [types-Pillow, types-PyYAML, types-requests]
exclude: '\.ipynb$'
args: [
--explicit-package-bases,
--ignore-missing-imports,
--config-file=pyproject.toml,
--exclude, 'scripts/benchmark_inference\.py',
Expand Down
1 change: 1 addition & 0 deletions benchmarks/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Benchmarks package for LandmarkDiff performance testing."""
6 changes: 3 additions & 3 deletions landmarkdiff/api_client_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async def main():
import base64
import logging
from pathlib import Path
from typing import Any
from typing import Any, cast

import cv2
import numpy as np
Expand Down Expand Up @@ -91,7 +91,7 @@ async def _handle_response(self, resp: Any) -> dict[str, Any]:
if resp.status >= 400:
text = await resp.text()
raise LandmarkDiffAPIError(f"Server returned {resp.status}: {text[:200]}")
return await resp.json()
return cast(dict[str, Any], await resp.json())

# ------------------------------------------------------------------
# API methods
Expand Down Expand Up @@ -124,7 +124,7 @@ async def procedures(self) -> list[str]:
try:
async with session.get(f"{self.base_url}/procedures") as resp:
data = await self._handle_response(resp)
return data.get("procedures", [])
return cast(list[str], data.get("procedures", []))
except LandmarkDiffAPIError:
raise
except Exception as e:
Expand Down
9 changes: 5 additions & 4 deletions landmarkdiff/comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from __future__ import annotations

import logging
from typing import cast

import cv2
import numpy as np
Expand Down Expand Up @@ -47,7 +48,7 @@ def create_slider_composite(
if line_width > 0 and 0 < split_x < w:
cv2.line(result, (split_x, 0), (split_x, h - 1), line_color, line_width)

return result
return cast(np.ndarray, result)


def create_side_by_side(
Expand Down Expand Up @@ -101,7 +102,7 @@ def create_side_by_side(
cv2.LINE_AA,
)

return canvas
return cast(np.ndarray, canvas)


def create_difference_heatmap(
Expand All @@ -127,7 +128,7 @@ def create_difference_heatmap(
diff = cv2.absdiff(original, pred)
gray_diff = cv2.cvtColor(diff, cv2.COLOR_BGR2GRAY)
amplified = np.clip(gray_diff.astype(np.float32) * amplify, 0, 255).astype(np.uint8)
return cv2.applyColorMap(amplified, colormap)
return cast(np.ndarray, cv2.applyColorMap(amplified, colormap))


def create_checkerboard_blend(
Expand Down Expand Up @@ -166,4 +167,4 @@ def create_checkerboard_blend(

mask_3ch = np.stack([mask] * 3, axis=-1)
result = original.astype(np.float32) * mask_3ch + pred.astype(np.float32) * (1.0 - mask_3ch)
return np.clip(result, 0, 255).astype(np.uint8)
return cast(np.ndarray, np.clip(result, 0, 255).astype(np.uint8))
3 changes: 2 additions & 1 deletion landmarkdiff/planning.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from __future__ import annotations

from dataclasses import dataclass
from typing import cast

import cv2
import numpy as np
Expand Down Expand Up @@ -214,4 +215,4 @@ def visualize_planning(
cv2.LINE_AA,
)

return canvas
return cast(np.ndarray, canvas)
21 changes: 16 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -192,16 +192,19 @@ ignore = [

[tool.mypy]
python_version = "3.10"
warn_return_any = false
warn_return_any = true
warn_unused_configs = true
disallow_untyped_defs = false
check_untyped_defs = false
disallow_untyped_defs = true
check_untyped_defs = true
explicit_package_bases = true
ignore_missing_imports = true
strict_optional = true
warn_redundant_casts = true
warn_unused_ignores = true
exclude = [
"scripts/batch_inference.py",
"scripts/benchmark_inference.py",
"examples/*.ipynb",
"tests/*.py",
"examples/",
]

[[tool.mypy.overrides]]
Expand Down Expand Up @@ -246,3 +249,11 @@ ignore_errors = true
[[tool.mypy.overrides]]
module = ["scripts.*"]
ignore_errors = true

[[tool.mypy.overrides]]
module = ["tests.*"]
ignore_errors = true

[[tool.mypy.overrides]]
module = ["examples.*"]
ignore_errors = true
1 change: 1 addition & 0 deletions scripts/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Scripts package for LandmarkDiff utilities and experiments."""
Loading