【问题标题】:How can I compute the hessian of the loss function in MXNet?如何计算 MXNet 中损失函数的粗麻布?
【发布时间】:2018-07-01 19:04:47
【问题描述】:

我目前正在学习 MXNet,并且正在使用神经网络解决一个问题。我有兴趣观察我的损失函数相对于网络权重的曲率,但尽我所能告诉神经网络函数目前不支持高阶梯度。是否有任何(可能是 hacky)方法我仍然可以做到这一点?

【问题讨论】:

    标签: python neural-network gradient data-science mxnet


    【解决方案1】:

    您可以关注here讨论

    它的要点是目前并非所有运算符都支持高阶梯度。

    在 Gluon 中,您可以尝试以下操作:

    with mx.autograd.record():
      output = net(x)
      loss = loss_func(output)
      dz = mx.autograd.grad(loss, [z], create_graph=True)  # where [z] is the parameter(s) you want
    
    dz[0].backward()  # now the actual parameters should have second order gradients
    

    取自forum thread

    【讨论】:

      猜你喜欢
      • 2014-06-11
      • 1970-01-01
      • 1970-01-01
      • 2018-05-26
      • 2018-01-30
      • 2023-01-11
      • 1970-01-01
      • 2021-10-07
      • 1970-01-01
      相关资源
      最近更新 更多