Coder Social home page Coder Social logo

Comments (8)

eric-tramel avatar eric-tramel commented on May 17, 2024

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.

eric-tramel avatar eric-tramel commented on May 17, 2024

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.

raghakot avatar raghakot commented on May 17, 2024

Fixed in latest.

from keras-vis.

DylanCope avatar DylanCope commented on May 17, 2024

@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.

raghakot avatar raghakot commented on May 17, 2024

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.

raghakot avatar raghakot commented on May 17, 2024

Feel free to reopen if you are seeing issues. There is no point in closing issues if the fix doesnt work.

from keras-vis.

DylanCope avatar DylanCope commented on May 17, 2024

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.
heatmap
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.

raghakot avatar raghakot commented on May 17, 2024

Try gradCAM. it usually gives better results.

from keras-vis.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.