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

[BUG] Heatmap generation error #360

Closed
jziggles opened this issue Apr 22, 2024 · 4 comments
Closed

[BUG] Heatmap generation error #360

jziggles opened this issue Apr 22, 2024 · 4 comments
Assignees
Labels
bug Something isn't working fixed Issue fixed, pending release

Comments

@jziggles
Copy link

I receive the following error with executing train_mil function below. I am using clam_mb as my MIL model. Please note that the code executes totally fine/completes when I do not include attention heatmaps. When using other MIL models (attention_mil) the heatmaps are generated fine without a problem. It would appear as though imshow is getting a 3D array with inappropriate dimensions (I believe the final dimension = 2 is the error?).
for train, val in splits:
P.train_mil(
config=config,
outcomes='ER_Status_By_IHC',
train_dataset=train,
val_dataset=val,
bags=('./path/pt_files/' + 'resnet50_postconv' + '/'),
attention_heatmaps=True,
cmap='cividis',
interpolation=None
)

Python 3.12.2
Slideflow 2.3.1

Traceback (most recent call last):

File "/XXX/path/slideflow/full_mil_clam.py", line 69, in

P.train_mil(

File "/home/jrg97/.conda/envs/slideflow-env/lib/python3.12/site-packages/slideflow/project.py", line 3985, in train_mil

return train_mil(

^^^^^^^^^^

File "/home/jrg97/.conda/envs/slideflow-env/lib/python3.12/site-packages/slideflow/mil/train/init.py", line 80, in train_mil

return _train_mil(config, **mil_kwargs)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/home/jrg97/.conda/envs/slideflow-env/lib/python3.12/site-packages/slideflow/mil/train/init.py", line 157, in _train_mil

return train_fn(

^^^^^^^^^

File "/home/jrg97/.conda/envs/slideflow-env/lib/python3.12/site-packages/slideflow/mil/train/init.py", line 786, in train_fastai

generate_attention_heatmaps(

File "/home/jrg97/.conda/envs/slideflow-env/lib/python3.12/site-packages/slideflow/mil/eval.py", line 824, in generate_attention_heatmaps

sf.util.location_heatmap(

File "/home/jrg97/.conda/envs/slideflow-env/lib/python3.12/site-packages/slideflow/util/init.py", line 1361, in location_heatmap

ax.imshow(

File "/home/jrg97/.conda/envs/slideflow-env/lib/python3.12/site-packages/matplotlib/init.py", line 1465, in inner

return func(ax, map(sanitize_sequence, args), *kwargs)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/home/jrg97/.conda/envs/slideflow-env/lib/python3.12/site-packages/matplotlib/axes/_axes.py", line 5759, in imshow

im.set_data(X)

File "/home/jrg97/.conda/envs/slideflow-env/lib/python3.12/site-packages/matplotlib/image.py", line 723, in set_data

self._A = self._normalize_image_array(A)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/home/jrg97/.conda/envs/slideflow-env/lib/python3.12/site-packages/matplotlib/image.py", line 693, in _normalize_image_array

raise TypeError(f"Invalid shape {A.shape} for image data")

TypeError: Invalid shape (27, 66, 2) for image data

@jziggles jziggles added the bug Something isn't working label Apr 22, 2024
@jziggles jziggles changed the title [BUG] Placeholder title [BUG] Heatmap generation error Apr 22, 2024
@jamesdolezal
Copy link
Collaborator

I apologize that it took so long for us to get to this - we do have a potential fix for this issue on our development branch, dev. This will be incorporated into our next 2.4.0 feature release.

@jamesdolezal jamesdolezal self-assigned this Jul 24, 2024
@jamesdolezal
Copy link
Collaborator

jamesdolezal commented Jul 31, 2024

Quick update - I can confirm that this issue is still present on dev. The error stems from the fact that CLAM_MB yields multi-dimensional attention (one value for each outcome class), rather than other models which yield a single attention score for each tile. This is causing issues with attention heatmap generation, both during training (as you've noted here) and in Slideflow Studio.

The fix will be to generate multiple attention maps, one for each outcome, for models like CLAM_MB that result in multiple attention values. I expect a fix in the next few days.

Edit: fix for training (as reported here) is up on dev. Fix for Slideflow Studio still in process.

jamesdolezal added a commit that referenced this issue Jul 31, 2024
…ng MIL training [#360]

- TODO: extend this support for Slideflow Studio
@jamesdolezal jamesdolezal added the fixed Issue fixed, pending release label Jul 31, 2024
@jamesdolezal
Copy link
Collaborator

This has now been fixed and will be included in version 2.4.0.

jamesdolezal added a commit that referenced this issue Aug 9, 2024
…ng MIL training [#360]

- TODO: extend this support for Slideflow Studio
@jamesdolezal
Copy link
Collaborator

Fixed and released in 2.3.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed Issue fixed, pending release
Projects
None yet
Development

No branches or pull requests

2 participants