Skip to content

ENH: Use log scale for attention heatmaps plots #804

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
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
4 changes: 3 additions & 1 deletion hi-ml-cpath/src/health_cpath/utils/viz_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from pathlib import Path
from typing import Sequence, List, Any, Dict, Optional, Union, Tuple

from matplotlib.colors import LogNorm
from monai.data.dataset import Dataset
from torch.utils.data import DataLoader
from health_cpath.datasets.panda_dataset import PandaDataset
Expand Down Expand Up @@ -229,7 +230,8 @@ def _get_slide_image_from_slide_dict(slide_dict: Dict[SlideKey, Any]) -> np.ndar
rects = [patches.Rectangle(xy, tile_size, tile_size) for xy in zip(tile_xs, tile_ys)]

# line width is set to 0 to avoid the black border around the tiles as the tiles are already colored
pc = collection.PatchCollection(rects, match_original=True, cmap=cmap, alpha=0.5, linewidth=0)
pc = collection.PatchCollection(rects, match_original=True, cmap=cmap, alpha=0.5, linewidth=0,
norm=LogNorm())
pc.set_array(np.array(attentions))
ax1.add_collection(pc)
cb = plt.colorbar(pc, cax=cax) # add colorbar to the right of the plot (cax)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion hi-ml-cpath/testhisto/testhisto/utils/test_viz_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def test_plot_heatmap_overlay(add_extra_slide_plot: bool, test_output_dirs: Outp
assert file.exists()
expected = full_ml_test_data_path("histo_heatmaps") / filename
# To update the stored results, uncomment this line:
# expected.write_bytes(file.read_bytes())
expected.write_bytes(file.read_bytes())
assert_binary_files_match(file, expected)


Expand Down