PaddlePaddle / InterpretDL

InterpretDL: Interpretation of Deep Learning Models,基于『飞桨』的模型可解释性算法库。
https://interpretdl.readthedocs.io
Apache License 2.0
237 stars 38 forks source link

Tutorial error #63

Closed miaomaomiaomaoda closed 1 year ago

miaomaomiaomaoda commented 1 year ago

location: https://github.com/PaddlePaddle/InterpretDL/blob/master/tutorials/GradCAM_Segmentation.ipynb

🐛 Bug

in funciton GradCAMSegInterpreter._build_predict_fn( ).predict_fn( ) :

# paddle gradient computation changes since 2.4
paddle_version=tuple(map(int, paddle.__version__.split(".")))
if paddle_version>=(2,4,0):
       loss.backward(retain_graph=True) #since paddle 2.4
       gradients = paddle.grad(
             outputs=[target], inputs=[self._feature_maps[self._target_layer_name]])[0]
else:
       oss.backward()
       gradients = self._feature_maps[self._target_layer_name].grad

error: target is not defined,it should be loss

holyseven commented 1 year ago

Thanks for pointing this out! We tested on 2.3.2 and didn't find the error with 2.4+.

After changing target to loss, is it working now? Would you mind proposing a PR to fix this issue?

miaomaomiaomaoda commented 1 year ago

yeah. After the change, it works very well. I will propose a PR later.

holyseven commented 1 year ago

Thanks!