-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Oge Marques
authored and
Oge Marques
committed
Jul 28, 2021
1 parent
9d64712
commit 20b683c
Showing
31 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,33 @@ | ||
# xai-matlab | ||
# Explainable AI for Medical Images | ||
This repository shows an example of how to use MATLAB to produce post-hoc explanations (using [Grad-CAM](https://www.mathworks.com/help/deeplearning/ref/gradcam.html) and [image LIME](https://www.mathworks.com/help/deeplearning/ref/imagelime.html)) for a medical image classification task. | ||
|
||
Both methods (`gradCAM` and `imageLIME`) are available as part of the MATLAB Deep Learning toolbox and require only a single line of code to be applied to results of predictions made by a deep neural network (plus a few lines of code to display the results as a colormap overlaid on the actual images). | ||
|
||
| ![](figures/pa_lateral_gradCAM.png) | | ||
|:--:| | ||
| Example of `gradCAM` results.| | ||
|
||
| ![](figures/pa_lateral_lime.png) | | ||
|:--:| | ||
| Example of `imageLIME` results.| | ||
## Experiment objective | ||
Given a chest x-ray (CXR), our solution should classify it into Posteroanterior (PA) or Lateral (L) view. | ||
### Dataset | ||
A small subset of the [PadChest](https://bimcv.cipf.es/bimcv-projects/padchest/) dataset<sup>[1](#myfootnote1)</sup>. | ||
## Requirements | ||
- [X] [MATLAB 2020a](https://www.mathworks.com/products/matlab.html) or later | ||
- [X] [Deep Learning Toolbox](https://www.mathworks.com/products/deep-learning.html) | ||
- [X] [Deep Learning Toolbox™ Model for SqueezeNet Network support package](https://www.mathworks.com/help/deeplearning/ref/squeezenet.html) | ||
- [ ] [Parallel Computing Toolbox](https://www.mathworks.com/products/parallel-computing.html) (only required for training using a GPU) | ||
## Suggested steps | ||
1. Download or clone the repository. | ||
2. Open MATLAB. | ||
3. Edit the contents of the `dataFolder` variable in the `xai_medical.mlx` file to reflect the path to your selected dataset. | ||
4. Run the `xai_medical.mlx` script and inspect results. | ||
## Additional remarks | ||
|
||
- You are encouraged to expand and adapt the example to your needs. | ||
- The choice of pretrained network and hyperparameters (learning rate, mini-batch size, number of epochs, etc.) is merely illustrative. | ||
- You are encouraged to (use Experiment Manager app to) tweak those choices and find a better solution. | ||
## Notes | ||
<a name="myfootnote1">[1]</a> This example uses a small subset of images to make it easier to get started without having to worry about large downloads and long training times. |
Binary file not shown.
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.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+6.15 MB
sample_rgb/lateral/126397712012687540784611673197697059691_fp0cu9_imrgb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.41 MB
..._rgb/lateral/216840111366964012373310883942009084123158919_00-069-064_imrgb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.32 MB
..._rgb/lateral/216840111366964012558082906712010004133151165_00-119-134_imrgb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+7.77 MB
..._rgb/lateral/216840111366964013340662495472012111130929144_01-108-133_imrgb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.68 MB
..._rgb/lateral/216840111366964013451228379692012257110540618_02-006-005_imrgb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.65 MB
..._rgb/lateral/216840111366964014008416513202014153161516671_01-196-149_imrgb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+11.5 MB
sample_rgb/lateral/317759408657031098460852906419716899073_2rq56f_imrgb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
function results = myimfcn(im) | ||
%Image Processing Function | ||
% | ||
% IM - Input image. | ||
% RESULTS - A scalar structure with the processing results. | ||
% | ||
|
||
%-------------------------------------------------------------------------- | ||
% Auto-generated by imageBatchProcessor App. | ||
% | ||
% When used by the App, this function will be called for every input image | ||
% file automatically. IM contains the input image as a matrix. RESULTS is a | ||
% scalar structure containing the results of this processing function. | ||
% | ||
%-------------------------------------------------------------------------- | ||
|
||
|
||
|
||
% Replace the sample below with your code---------------------------------- | ||
|
||
if(size(im,3)==1) | ||
% Convert grayscale to RGB | ||
imrgb(:,:,1) = im; | ||
imrgb(:,:,2) = im; | ||
imrgb(:,:,3) = im; | ||
else | ||
imrgb = im; | ||
end | ||
|
||
results.imrgb = imrgb; | ||
%-------------------------------------------------------------------------- |
Oops, something went wrong.