Comments (8)
my codes are:
gMLP_PATH = "./final.pdparams"
gMLP = gMLPVision(
image_size = 32,
patch_size = 2,
num_classes = 10,
dim = 128,
depth = 30
)
gMLP_state_dict = paddle.load(gMLP_PATH)
gMLP.set_dict(gMLP_state_dict)
gradcam = it.GradCAMInterpreter(gMLP, use_cuda=False)
heatmap = gradcam.interpret(
"./5.png",
'layers.29.fn.fn.sgu',
# labels=None,
visual=False,
save_path="./5view.png")
from interpretdl.
my package version is:
paddlepaddle==2.0.0
interpretdl==0.2.2
from interpretdl.
Hi @zbp-xxxp ,
It seems an error of using ssh and matplotlib. The solution that I found from here may help you out:
sudo pip uninstall matplotlib
sudo apt-get install python-matplotlib
Some comments from that issue may be also helpful.
from interpretdl.
/usr/lib/python3/dist-packages/matplotlib/backend_bases.py:57: DeprecationWarning: PILLOW_VERSION is deprecated and will be removed in Pillow 9 (2022-01-02). Use version instead.
from PIL import PILLOW_VERSION
Killed
from interpretdl.
Sorry I cannot reproduce this error. Could you try to run the code on a local machine if you did not? or try to create a new Python environment.
from interpretdl.
RD您好,是这样的,我用中文跟您说吧。
我跑基于模型中间特征解析模型的代码(GradCAM,ScoreCAM)的时候,AI Studio会卡死直到内存溢出,我在本地机器跑会直接被kill掉,就像上面提的那个一样。
我的模型是gMLP,基于输入特征解析模型的代码(LIMECVInterpreter)是可以跑通的。
但是我需要可视化的是网络中每一层的权重,而不是训练一个子网络检验模型性能,因此还是需要基于模型中间特征去解析模型。
我分析了一下跑不通的原因,不知道对不对:gMLP有to patch的操作,会不会是这个操作导致了这个问题?如果是,有什么方法可以解决吗?
to patch代码:
class PatchEmbed(nn.Layer):
""" Image to Patch Embedding
"""
def __init__(self, img_size=32, patch_size=16, in_chans=3, embed_dim=768):
super(PatchEmbed, self).__init__()
img_size = (img_size, img_size)
patch_size = (patch_size, patch_size)
num_patches = (img_size[1] // patch_size[1]) * (img_size[0] // patch_size[0])
self.img_size = img_size
self.patch_size = patch_size
self.num_patches = num_patches
self.project = nn.Conv2D(in_chans, embed_dim, kernel_size=self.patch_size, stride=self.patch_size)
def forward(self, x):
x = self.project(x)
x = x.flatten(2)
x = paddle.transpose(x, perm=[0, 2, 1])
return x
from interpretdl.
不太确定是哪一个步骤导致上述问题,如果有更详细的代码可以更深入分析。
如果是有关gradient的计算的话,可以参考这个issue。我们计算gradient的代码之后也会更新。
import paddle
from interpretdl.data_processor.readers import preprocess_inputs
from datetime import datetime
import numpy as np
img_path = 'assets/catdog.png'
# read the image and scale to [0, 1] with substract mean and divided by std.
data = np.random.rand(1, 3, 224, 224).astype(np.float32)
# imgs, data = preprocess_inputs(img_path, [224, 224, 3])
print(data.shape, data.dtype)
# print(imgs.shape, data.shape) # (1, 224, 224, 3) (1, 3, 224, 224)
# from paddle.vision.models import resnet101, resnet50, mobilenet_v2, vgg13, vgg19
# paddle_model = resnet101(pretrained=False)
from assets.vision_transformer import ViT_small_patch16_224
# https://github.com/PaddlePaddle/PaddleClas/blob/release/2.2/ppcls/arch/backbone/model_zoo/vision_transformer.py
paddle_model = ViT_small_patch16_224()
MODEL_PATH = 'assets/ViT_small_patch16_224_pretrained.pdparams'
paddle_model.set_dict(paddle.load(MODEL_PATH))
data = paddle.to_tensor(data)
data.stop_gradient = False
out = paddle_model(data)
preds = paddle.argmax(out, axis=1)
label_onehot = paddle.nn.functional.one_hot(
paddle.to_tensor(preds), num_classes=out.shape[1])
target = paddle.sum(out * label_onehot, axis=1)
now = datetime.now()
# g = paddle.grad(outputs=target, inputs=data)[0]
target.backward()
g = data.grad
print(datetime.now() - now)
from interpretdl.
Free to reopen the issue if there are more questions.
from interpretdl.
Related Issues (20)
- 运行example_grad_cam_cv.ipynb时报错 HOT 3
- 热力图 HOT 7
- 关于分割模型的可视化 HOT 5
- Infidelity metric not found, probably a new release needed HOT 1
- Interface
- 长宽不相等的图像怎么输入 HOT 5
- Gradient computation changed since paddle2.4
- 分割可视化 HOT 25
- Shapely Value HOT 7
- Grad-CAM可视化分割模型 HOT 2
- GradcamSeg是否支持paddle2.4以上版本? HOT 1
- 请问这里边有没有和自然语言处理相关的 HOT 7
- softmax(): argument 'x' (position 0) must be Tensor, but got list HOT 3
- Tutorial error HOT 3
- Failed to apply gradcam on mobileNetv3-large HOT 6
- 在语义分割中应用GradCAM时,如何对整幅图像进行热力图显示,传入的pixels大小如何确定 HOT 2
- 怎么拿出paddledetection中间的某一层进行可视化 HOT 1
- wrong url HOT 2
- UFuncTypeError: Cannot cast ufunc 'add' output from dtype('O') to dtype('float64') with casting rule 'same_kind' HOT 6
- pip install interpretdl ERROR: Failed building wheel for scikit-learn HOT 5
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 interpretdl.