Skip to content

Commit

Permalink
Merge pull request #172 from XAITK/update-t-v0.12.0
Browse files Browse the repository at this point in the history
Update to v0.12.0
  • Loading branch information
eveenhuis authored Jan 20, 2025
2 parents bbeb475 + 6a9aa8a commit ef44048
Show file tree
Hide file tree
Showing 8 changed files with 491 additions and 19 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/.github-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,36 @@ jobs:
run: poetry run mypy --config-file pyproject.toml src/ tests/
shell: bash

pyright:
runs-on: ubuntu-latest
container: python:3.9
steps:
- name: Install Git LFS
run: |
apt-get -qq update
apt-get -qq install -y git-lfs
shell: bash
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4
with:
fetch-depth: 0
lfs: true
# Cache local python environment artifacts for the current python version
# and poetry lockfile hash.
- uses: actions/cache@v4
id: env-cache
with:
# Confirmed that the `.local` directory doesn't exist until the
# `pip install --user` is invoked below, so we can be confident that
# only our python stuff is being captured in this cache (intentional).
path: ~/.cache
key: python-3.9-${{ hashFiles('poetry.lock') }}
- name: Setup Environment
uses: ./.github/actions/quality-stage
- name: Typecheck with pyright
run: poetry run pyright
shell: bash

ruff-lint:
runs-on: ubuntu-latest
container: python:3.9
Expand Down
1 change: 1 addition & 0 deletions .gitlab-ci/.gitlab-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ notebooks:
"SimilarityScoring.ipynb",
"SuperPixelSaliency.ipynb",
"VIAME_OcclusionSaliency.ipynb",
"MC_RISE.ipynb",
# # Shared memory issue on GitLab
# "SerializedDetectionSaliency.ipynb",
# Model comparison example is excluded due to computational complexity
Expand Down
1 change: 1 addition & 0 deletions docs/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ Release Notes
release_notes/v0.9.2
release_notes/v0.10.0
release_notes/v0.11.0
release_notes/v0.12.0
15 changes: 15 additions & 0 deletions docs/release_notes/v0.12.0.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
v0.12.0
=======

Bug fix for ``MC-RISE`` when threading is utilized, plus exemplar notebook demonstrating its use.

Updates / New Features
----------------------

Examples

* Added the ``MC-RISE`` example notebook that demonstrates the MC-RISE saliency
algorithm on a sample image from the GTSRB dataset.

Fixes
-----
376 changes: 376 additions & 0 deletions examples/MC_RISE.ipynb

Large diffs are not rendered by default.

52 changes: 39 additions & 13 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 21 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ classifiers = [
# :auto package-meta:
# package-specific meta, don't put this in "generated package-meta"
authors = ["Kitware, Inc. <[email protected]>"]
version = "0.11.0"
version = "0.12.0"
description = "Visual saliency map generation interfaces and baseline implementations for explainable AI."

[tool.poetry.dependencies]
Expand Down Expand Up @@ -105,6 +105,7 @@ pre-commit = ">=2.20"
ruff = "^0.5.6"
types-setuptools = ">=65.6.0.1"
sphinx-lint = ">=1.0.0"
pyright = {version=">=1.1.320",extras=["nodejs"]}
# :auto linting:

# :auto docs:
Expand Down Expand Up @@ -245,3 +246,22 @@ incremental = false
module = "tests.*"
ignore_errors = true
# :auto mypy:

# :auto pyright:
[tool.pyright]
pythonVersion = "3.9"
reportMissingImports = "warning"
typeCheckingMode = "standard"
include = [
"src/xaitk_saliency",
"tests",
"examples"
]
exclude = [
"**/__pycache__",
"demos",
"scripts",
"docs/_build",
"docs/_implementations",
]
# :auto pyright:
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def __init__(
self._fill_colors = fill_colors

@staticmethod
def _work_func(*, ref_image: np.ndarray, i_: int, m: np.ndarray, f: np.ndarray) -> np.ndarray:
def _work_func(ref_image: np.ndarray, i_: int, m: np.ndarray, f: np.ndarray) -> np.ndarray:
s: tuple = (...,)
if ref_image.ndim > 2:
s = (..., None) # add channel axis for multiplication
Expand Down Expand Up @@ -104,12 +104,15 @@ def _occlude_image_streaming(
for i, (mask, fill) in enumerate(zip(masks, fill_values)):
yield MCRISEStack._work_func(ref_image=ref_image, i_=i, m=mask, f=fill)
else:
ref_image = np.stack([ref_image for _ in fill_values], axis=0)
# NOTE: Never pass by keyword to avoid the iterables being wrongly
# zipped and assigned to kwargs.
yield from parallel_map(
MCRISEStack._work_func,
ref_image=ref_image,
i_=itertools.count(),
m=masks,
f=fill_values,
ref_image,
itertools.count(),
masks,
fill_values,
cores=threads,
use_multiprocessing=False,
)
Expand Down

0 comments on commit ef44048

Please sign in to comment.