GithubHelp home page GithubHelp logo

Saliency maps numpy divide about keras-vis HOT 7 CLOSED

raghakot avatar raghakot commented on July 26, 2024 1
Saliency maps numpy divide

from keras-vis.

Comments (7)

raghakot avatar raghakot commented on July 26, 2024 3

Just letting you guys know that I looked into it. I have it fixed but i ended up making a whole bunch of efficiency improvements which i plan to get out together. I will try my best to get it wrapped up this weekend.

from keras-vis.

sakares avatar sakares commented on July 26, 2024 2

In the file visualization.py under vis/utils directory which is based on your python site-package installation path,
I have made a change from
grads /= np.max(grads)
to
grads = np.true_divide(grads, np.max(grads))

However, I got a bug complained about:

heatmap = cv2.applyColorMap(cv2.GaussianBlur(grads * 255, (3, 3), 0), cv2.COLORMAP_JET)

error: /Users/travis/build/skvark/opencv-python/opencv/modules/imgproc/src/colormap.cpp:501: error: (-5) cv::ColorMap only supports source images of type CV_8UC1 or CV_8UC3 in function operator()
on the line

any idea?

Update: I just made a change by changing from
heatmap = cv2.applyColorMap(cv2.GaussianBlur(grads * 255, (3, 3), 0), cv2.COLORMAP_JET)
to
heatmap = cv2.applyColorMap(cv2.GaussianBlur(grads.astype(np.uint8) * 255, (3, 3), 0), cv2.COLORMAP_JET)

from keras-vis.

raghakot avatar raghakot commented on July 26, 2024

Which version of numpy are you using? I cant reproduce this. Perhaps try a newer version of numpy?
The tests runs this example and its passing.

from keras-vis.

fredhohman avatar fredhohman commented on July 26, 2024

Thanks for the quick response!
I'm using 1.12.1, but still isn't working.
Is there something else I can provide to help debug?

from keras-vis.

andyfangdz avatar andyfangdz commented on July 26, 2024

I also had the same error. Looks like numpy had a breaking change in their API: numpy/numpy#6464

My script also complained about missing a imagenet_class_index.json file. Here's the traceback:

Traceback (most recent call last):
  File "try.py", line 35, in <module>
    heatmap = visualize_saliency(model, layer_idx, [pred_class], seed_img, text=utils.get_imagenet_label(pred_class))
  File "/Users/andy/anaconda/lib/python3.5/site-packages/vis/utils/utils.py", line 185, in get_imagenet_label
    with open(os.path.join(os.path.dirname(__file__), '../../resources/imagenet_class_index.json')) as f:
FileNotFoundError: [Errno 2] No such file or directory: '/Users/andy/anaconda/lib/python3.5/site-packages/vis/utils/../../resources/imagenet_class_index.json'

Looks like there's an extra .. in the path? I did find the json file here, but the path should be vis/utils/../resources/imagenet_class_index.json: https://github.com/raghakot/keras-vis/blob/master/resources/imagenet_class_index.json

from keras-vis.

raghakot avatar raghakot commented on July 26, 2024

Sorry this took a while. I just pushed a bunch of updates. These issues should now be fixed.

from keras-vis.

raghakot avatar raghakot commented on July 26, 2024

Feel free to reopen if you continue to see the issue,

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.