【问题标题】:PyTorch - How to get the gradient of the first layer relative to the input?PyTorch - 如何获得第一层相对于输入的梯度?
【发布时间】:2019-11-07 15:09:16
【问题描述】:

根据我的理解,通过使用反向挂钩,索引 0 处的梯度输入为我提供了相对于输入的梯度。这适用于所有图层,除了第一个图层。在这一个中,索引 0 处的值为 None。

有人能解释一下如何在 PyTorch 中获得与输入图像相关的渐变吗?

向后挂钩的 PyTorch 文档和示例:https://pytorch.org/docs/stable/nn.html#torch.nn.Module.register_backward_hook https://pytorch.org/tutorials/beginner/former_torchies/nnft_tutorial.html#forward-and-backward-function-hooks

【问题讨论】:

    标签: python machine-learning hook pytorch


    【解决方案1】:

    我只是忘记为我的输入数据设置 .requires_grad_()。现在我得到渐变而不是无。 :D

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-18
      • 1970-01-01
      • 2022-01-14
      • 1970-01-01
      • 1970-01-01
      • 2022-01-13
      • 1970-01-01
      • 2019-01-05
      相关资源
      最近更新 更多