Skip to content

ViT 可解释代码无法运行 #74

Description

@SonoHistology

尝试用可解释代码运行自己训练的ViT_small_patch16_224, 遇到了一些问题,请问有没有什么建议:
1) sg = it.SmoothGradInterpreter(paddle_model, device='cpu')

gradients = sg.interpret(
img_path,
noise_amount=0.1,
visual=True,
labels=None,
save_path=None)

该程序运行出的结果有斑块状噪声

Image

2) 运行以下程序会报错:

tam = it.TAMInterpreter(paddle_model, device='cpu')

heatmap = tam.interpret(
img_path,
start_layer=4,
label=None, # cat
visual=True,
save_path=None)

错误如下:

TAMInterpreter.interpret(self, inputs, start_layer, steps, label, resize_to, crop_to, visual, save_path)
96 data_scaled = data * alpha
97 _, gradients, _ = self.predict_fn(data_scaled, label=label)
---> 99 total_gradients += gradients
101 W_state = np.mean((total_gradients / steps).clip(min=0), axis=1)[:, 0, :].reshape((b, 1, s))
103 tam_explanation = (states * W_state)[:, 0, 1:].reshape((-1, 14, 14))

UFuncTypeError: Cannot cast ufunc 'add' output from dtype('O') to dtype('float64') with casting rule 'same_kind'

3)运行以下程序会报错:

bt = it.BTCVInterpreter(paddle_model, device='gpu:0')

heatmap = bt.interpret(
img_path,
ap_mode = 'head',
start_layer=4,
label=None, # cat
visual=True,
save_path=None)

错误如下:

495 raise ValueError("gradient_of should be one of [logits, probability].")
497 for i, attn in enumerate(block_attns):
--> 498 grad = attn.grad.numpy()
499 block_attns_grads.append(grad)
500 block_attns[i] = attn.numpy()

AttributeError: 'NoneType' object has no attribute 'numpy'

No activity

Activity on this issue will appear here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions