albermax / innvestigate

A toolbox to iNNvestigate neural networks' predictions!
Other
1.27k stars 233 forks source link

perturbation_analysis for 2D and 1D data. #166

Open Abdullah00Alharthi opened 5 years ago

Abdullah00Alharthi commented 5 years ago

Many thanks for this great repository.

I have been trying to run the perturbation analysis on a 2D and 1D data. I've been getting the error , and I just can't get around it.

axis = tuple(normalize_axis_index(ax, ndim, argname) for ax in axis) AxisError: source: axis 3 is out of bounds for array of dimension 3

I know this have to do with the data shape because when I reshape the data to 3D as (m x n x k) for 2D CNN the methods work. However, I am trying to apply 1D CNN, where this type of network process 2D data. I want to preform the classification using 1D CNN with the 2D data and compere the performances of the networks on the data perturbation.

Also if possible I would like to use a linear models as in this paper | https://doi.org/10.1038/s41598-019-38748-8

Best regards

sebastian-lapuschkin commented 5 years ago

Hi @aalharthi1277,

can you post a full stack trace of the exception you are experiencing?

As a quick hack, I would suggest adding a dummy axis to your data. Assuming your (m x n x k ) means (sample-axis, [feature-axes]), you could extend your data, e.g. in numpy formulation, with

data_extended = data[..., None]  # yields a (m x n x k x 1) array

This should at a first glance resolve the missing-axis issue. After perturbation, you can remove the extra axis by explicitly indexing, i.e.

data = data_extended_and_perturbed[...,0]

if all else fails, have a look at the (organically grown and a bit messy) perturbation code in the repo to the paper you linked