Comments (8)
I'm having the same problem, using Anaconda with a Python 3.5 virtual environment running, so I'm also making use of OpenCV3. Here is the output and offending line:
Working on filters: [3]
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-15-4d1a18352923> in <module>()
4
5
----> 6 heatmap = visualize_saliency(faceNet, 7, yclas[idx], X[idx,:,:,:], text=names[yclas[idx]])
/Users/eric/anaconda/envs/tf35/lib/python3.5/site-packages/keras_vis-0.1.2-py3.5.egg/vis/visualization.py in visualize_saliency(model, layer_idx, filter_indices, seed_img, text, overlay)
151 ]
152 opt = Optimizer(model.input, losses)
--> 153 grads = opt.minimize(max_iter=1, verbose=False, jitter=0, seed_img=seed_img)[1]
154
155 # We are minimizing loss as opposed to maximizing output as with the paper.
TypeError: minimize() got an unexpected keyword argument 'jitter'
from keras-vis.
Additionally, if one removes the jitter
keyword from l.153 you are then presented with a new error when "smoothing the activation map"...
Working on filters: [3]
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-7-4d1a18352923> in <module>()
4
5
----> 6 heatmap = visualize_saliency(faceNet, 7, yclas[idx], X[idx,:,:,:], text=names[yclas[idx]])
/Users/eric/anaconda/envs/tf35/lib/python3.5/site-packages/keras_vis-0.1.2-py3.5.egg/vis/visualization.py in visualize_saliency(model, layer_idx, filter_indices, seed_img, text, overlay)
164 # Smoothen activation map
165 grads = utils.deprocess_image(grads[0])
--> 166 grads /= np.max(grads)
167
168 # Convert to heatmap and zero out low probabilities for a cleaner output.
TypeError: ufunc 'true_divide' output (typecode 'd') could not be coerced to provided output parameter (typecode 'B') according to the casting rule ''same_kind''
It seems this is coming from updates in NumPy. See NumPy issue #6464 here.
from keras-vis.
Fixed in latest.
from keras-vis.
@eric-tramel, I had the same issue when removing the argument, I solved it by replacing the line grads /= np.max(grads)
with grads = grads / np.max(grads)
. Also I installed the latest version of the package and this issue persists. On top of this I get an error for heatmap[np.where(grads <= 0.2)] = 0
. I fixed this by changing the shape of heatmap, which for some reason was of rank 2.
I don't know why I would be having these issues and you wouldn't, @raghakot. I would guess you've got an out of date version of numpy
.
from keras-vis.
Hmm, the tests pass on travis. I dont think its a numpy versioning issue. Can you post full example of what you are trying to run. Is it in theano?
from keras-vis.
Feel free to reopen if you are seeing issues. There is no point in closing issues if the fix doesnt work.
from keras-vis.
It doesn't seem right to reopen the issue, as the original issue in this thread was addressed. Also I did actually get the function working in the end, my final code looked like this,
# Smoothen activation map
grads = np.float32(utils.deprocess_image(grads[0]))
grads /= np.max(grads)
grads = cv2.cvtColor(grads, cv2.COLOR_GRAY2RGB)
blurred = np.uint8(cv2.GaussianBlur(255*grads, (3, 3), 0))
# Convert to heatmap and zero out low probabilities for a cleaner output.
heatmap = cv2.applyColorMap(blurred, cv2.COLORMAP_JET)
heatmap[np.where(grads <= 0.2)] = 0
I'm not sure if its actually giving the correct output, this is an example using the Xception model with ImageNet weights.
It seems reasonable, however it doesn't looked as blurred as the examples and hasn't been thresholded in the same way.
from keras-vis.
Try gradCAM. it usually gives better results.
from keras-vis.
Related Issues (20)
- [question] electrode contribution in EEG input
- Is there any reason why no demo for activation maximization for resnet?
- Is the project still maintained? HOT 2
- Exact gradient values
- Memory increases and iterations slow down while using visualize_saliency
- 3D MRI Image
- How to clip the positive gradients when using visualization_cam?
- AttributeError: module 'tensorflow' has no attribute 'get_default_graph' HOT 1
- AttributeError: 'list'/integer/float object has no attribute 'build_loss' in visualize_saliency_with_losses
- ImportError: cannot import name '_Conv' from 'keras.layers.convolutional' HOT 19
- Generated Image Color
- Issue - "ImportError: cannot import name '_Conv' from 'keras.layers.convolutional'" HOT 2
- Tensorflow version? HOT 1
- Problem with custom CNN VGG16 (unsupported operand type(s) for *: 'int' and 'NoneType')
- scipy 1.5.2 ImportError: cannot import name 'imresize' HOT 3
- Cannot convert a symbolic Keras input/output to a numpy array... HOT 1
- v
- Is this also working for Faster R-CNN or Mask R-CNN?
- Why is pre-activation output used for computing vanilla saliency map?
- AttributeError: module 'keras.utils.generic_utils' has no attribute 'populate_dict_with_module_objects'
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from keras-vis.