frankkramer-lab / aucmedi

a framework for Automated Classification of Medical Images
https://frankkramer-lab.github.io/aucmedi/
GNU General Public License v3.0
38 stars 12 forks source link

Error using Grad-CAM #181

Closed smcch closed 1 year ago

smcch commented 1 year ago

Hi! I have trained a model for classification using 3D nifti images (CT scans). But I get an error with XAI .

Windows 10 Python 3.9 Tensorflow 2.10 CUDA 11.2 cuDNN 8.1

Here my code:

gen_test = data_generator.DataGenerator( samples=set_test[0], labels=None, path_imagedir=r"C:****", image_format=image_format, data_aug=None, batch_size= 6, resize= model.meta_input, seed=100, loader=sitk_loader, subfunctions=sf_list )

model = model.NeuralNetwork( n_labels=nclasses, channels=3, architecture="3D.DenseNet201", pretrained_weights=use_pretrained, loss=loss, metrics=nn_metrics, activation_output=activation_function )

model.load(r"C:*****\model.best_loss.hdf5")

predictions = model.predict( prediction_generator=gen_test )

xai_decoder(gen_test, model, predictions, method="gradcam", out_path=r"C:******\xai")

The error:

Traceback (most recent call last): File "C:\Users***\AppData\Local\Programs\Python\Python39\lib\code.py", line 90, in runcode exec(code, self.locals) File "", line 1, in File "C:\Users***\PycharmProjects\HSA_CNN\venv\lib\site-packages\aucmedi\xai\decoder.py", line 90, in xai_decoder xai_method = xai_dict[method](model.model, layerName=layerName) File "C:\Users*\PycharmProjects\HSA_CNN\venv\lib\site-packages\aucmedi\xai\methods\gradcam.py", line 66, in init if self.layerName is None : self.layerName = self.find_output_layer() File "C:\Users**\PycharmProjects\HSA_CNN\venv\lib\site-packages\aucmedi\xai\methods\gradcam.py", line 83, in find_output_layer raise ValueError("Could not find 4D layer. Cannot apply Grad-CAM.") ValueError: Could not find 4D layer. Cannot apply Grad-CAM.

Thanks!

muellerdo commented 1 year ago

Hey @smcch,

sadly, 3D support for explainable AI is currently not supported by AUCMEDI. 😞

However, this feature is still on our internal roadmap to be included in the future.

Cheers, Dominik

smcch commented 1 year ago

Thanks @muellerdo !!!