primozgodec / keras-explain Goto Github PK
View Code? Open in Web Editor NEWThe toolkit to explain Keras model predictions.
License: MIT License
The toolkit to explain Keras model predictions.
License: MIT License
Traceback (most recent call last):
File "/home/xdjf/zingchen/keras_explain/test/test_lrp.py", line 44, in
Test_inception.test_lrp()
File "/home/xdjf/zingchen/keras_explain/test/test_lrp.py", line 40, in test_lrp
LRP, {"model": self.model}, self.images)
File "/home/xdjf/zingchen/keras_explain/test/test_lrp.py", line 34, in _test_approach
exp_pos, exp_neg = explainer.explain(image, 15)
File "/home/xdjf/anaconda3/envs/keras_explain/lib/python3.6/site-packages/keras_explain-0.0.1-py3.6.egg/keras_explain/lrp.py", line 33, in explain
File "/home/xdjf/anaconda3/envs/keras_explain/lib/python3.6/site-packages/keras_explain-0.0.1-py3.6.egg/keras_explain/lrp.py", line 134, in get_layers_outputs
AttributeError: 'NoneType' object has no attribute 'output'
Process finished with exit code 1
Hi Primoz,
i am trying to use your toolbox for visualizations of an inceptionv3 model.
When i try to transform the explanation array into an image i get the following error:
exp_heatmap = cv2.resize(exp_heatmap, (c_original.shape[1], c_original.shape[0])) TypeError: Expected cv::UMat for argument 'src'
see the following gist for code. https://gist.github.com/randmized/6c506086fb8e92518529c188ed22c558
could you elaborate on the output and how eventually getting an image written to file?
Also i was not able to find documentation other then https://pypi.org/project/keras-explain/ and the github repository.
all best
I tried to use "PredictionDiff" for MNIST images and found that it was coded to only accept RGB images. It was relatively easy for me to open the code and make it work for grayscale images.
I recommend adding variables that calculate the number of channels and use that instead of "3" everywhere in the code.
Hi,
I am trying to figure out how to use this toolbox (great project, btw, many thanks for creating it!). I took a model and an image an ran the Lime explainer for them with the correct class prediction - something reasonable came out. Then I randomly changed the target class index to 8 (the model has 89 classes so it's there all right) and got this error:
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-34-c7232aa8ce1b> in <module>()
7 print(classIdx, pred[0][classIdx])
8
----> 9 pos,neg = explainer.explain(img, 8)
/usr/local/lib/python3.6/site-packages/keras_explain/lime_ribeiro.py in explain(self, image, target_class)
16 image, self.model.predict, top_labels=5, num_samples=1000)
17 temp, mask = explanation.get_image_and_mask(
---> 18 target_class, positive_only=False, num_features=10, hide_rest=True)
19
20 return (mask == 2).astype(int), (mask == 1).astype(int)
/usr/local/lib/python3.6/site-packages/lime/lime_image.py in get_image_and_mask(self, label, positive_only, hide_rest, num_features, min_weight)
49 """
50 if label not in self.local_exp:
---> 51 raise KeyError('Label not in explanation')
52 segments = self.segments
53 image = self.image
KeyError: 'Label not in explanation'
Can you help me with this?
Thanks!
I'm currently working on image classification and I made a feature combination model using Resnet-50 and Xception. Can LRP method be applied to this model?
Thanks in advance !
If I ask for an explanation on a model with softmax as last layer i get:
LayerNotImplementedException
I think it can be easily removed simply not considering the last softmax layer
when I use padding='same' in conv2d layers i get error.
basic example:
m = Sequential()
m.add(Conv2D(512, kernel_size=(3, 3),
activation='relu', padding='same',
input_shape=(14,14,512),strides=(1,1)))
m.add(MaxPooling2D(pool_size=(2,2)))
m.summary()
explainer = LRP(m)
exp = explainer.explain(numpy.ones((14,14,512)), 3)[0]
error: ValueError: operands could not be broadcast together with shapes (1,3,3,512,512) (1,3,2,512,1)
this is a problem especially in already trained model (e.g., vgg16)
Loading model image and using any of the methods returns FailedPreconditionError
.
FailedPreconditionError: 2 root error(s) found.
(0) Failed precondition: Error while reading resource variable block5_conv1_2/kernel from Container: localhost. This could mean that the variable was uninitialized. Not found: Container localhost does not exist. (Could not find resource: localhost/block5_conv1_2/kernel)
[[{{node model_2/block5_conv1/Conv2D/ReadVariableOp}}]]
[[gradients/model_2/block1_conv1/Conv2D_grad/Conv2DBackpropInput/_11]]
(1) Failed precondition: Error while reading resource variable block5_conv1_2/kernel from Container: localhost. This could mean that the variable was uninitialized. Not found: Container localhost does not exist. (Could not find resource: localhost/block5_conv1_2/kernel)
[[{{node model_2/block5_conv1/Conv2D/ReadVariableOp}}]]
My code:
model = load_model(os.getcwd() + "/models/saved_models_for_fusion/0_FusionVGGMnistToPS.h5")
img_path = str(Path(os.getcwd() + "/models/scripts/xxx.jpg"))
img = load_img(img_path)
explainer = Saliency(model, layer=3)
exp = explainer.explain(img, 0)
I think that the resolution can be found here:
tensorflow/tensorflow#28287 (comment) is it possible to check whether this can fix this issue? It seems that loading model and using model.predict() fails due to not thread-safe operations.
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.