Giter VIP home page Giter VIP logo

Comments (5)

holyseven avatar holyseven commented on May 22, 2024

Hi @NICECPU

可视化的代码重构过,可参考GradCAM的例子

如果只是想用二值的可视化,可以直接用类似代码:

explanation_mask = np.zeros(explanation.shape, np.uint8)
explanation_mask[explanation > threshold] = 1

from interpretdl.

NICECPU avatar NICECPU commented on May 22, 2024

@holyseven ,十分感谢你的回复,我参考了GradCAM的代码,得到下面的程序
'''python
import numpy as np
import interpretdl as it
from matplotlib import pyplot as plt
from paddle.vision.models import resnet50
from PIL import Image
paddle_model = resnet50(pretrained=True) #获得模型
sg = it.SmoothGradInterpreter(paddle_model, use_cuda=True) #把模型加载到可解释性算法中,这里我们用的是SmoothGrad算法
gradients = sg.interpret('鹿.jpg', visual=True, save_path=None) #展示结果
explanation=gradients[0]
explanation=explanation.transpose(1,2,0)
image_2d = explanation[:,:,2]
percentile=99
vmax = np.percentile(image_2d, percentile)
vmin = np.min(image_2d)
x = np.clip((image_2d - vmin) / (vmax - vmin), 0, 1) * 255
x = np.uint8(x)
plt.imshow(x,'gray')
plt.axis("off")
plt.show()
'''
但是我的结果 却不像csdn 那样 我希望得到的是 激活和未激活部分的灰度图 不想得到原图的灰度 那样会对我的结果产生干扰
请问能不能解答一下 ?

from interpretdl.

holyseven avatar holyseven commented on May 22, 2024

改了一下后面的处理代码,利用阈值即可得到二值图:

image_2d = np.abs(explanation).sum(2)

percentile=90
threshold = np.percentile(image_2d, percentile)

explanation_mask = np.zeros(image_2d.shape, np.uint8)
explanation_mask[image_2d > threshold] = 1

plt.imshow(explanation_mask, 'gray')
plt.axis("off")
plt.show()

from interpretdl.

NICECPU avatar NICECPU commented on May 22, 2024

@holyseven 谢谢,十分感谢!我发现问题的关键了!

from interpretdl.

holyseven avatar holyseven commented on May 22, 2024

Free to reopen the issue for more questions.

from interpretdl.

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.