# How to compute hessian

**URL:** https://discourse.julialang.org/t/how-to-compute-hessian/28012
**Category:** Machine Learning
**Created:** [August 26, 2019, 9:11pm UTC](https://discourse.julialang.org/t/how-to-compute-hessian/28012 "2019-08-26T21:11:33Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![stochastic\_guy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stochastic_guy/32/9877_2.png) [@stochastic\_guy](https://discourse.julialang.org/u/stochastic_guy)
#### Post date: [August 26, 2019, 9:11pm UTC](https://discourse.julialang.org/t/how-to-compute-hessian/28012/1 "2019-08-26T21:11:33Z")

</div>

**New to Flux!**  
I want to compute the gradient and hessian for this loss function.

```julia
loss(x,y) = -sum(y.*log.(model(x)) .- (1 .- y).*log.(1 .- model(x))) * 1 // size(y, 2)

```

where

```julia
model = Flux.Dense(in,out,σ)

```

And how do you access the final values for hessain and gradient once the training is over

---

<div class="post-metadata">

### Author: ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)
#### Post date: [August 26, 2019, 11:14pm UTC](https://discourse.julialang.org/t/how-to-compute-hessian/28012/2 "2019-08-26T23:14:08Z")

</div>

> [@\[Flux\] Issue while computing Hessian MethodError: objects of type Tracker.Grads are not callable](https://discourse.julialang.org/t/flux-issue-while-computing-hessian-methoderror-objects-of-type-tracker-grads-are-not-callable/27980):
>
> I’m new to Flux and I’m trying to compute the hessian. Here’s the code: grad = Flux.gradient(() -\> loss(x, y), Flux.params(model)) hess = Flux.gradient(grad, Flux.params(model)) But when running the line to compute hessian, it’s throwing the following error MethodError: objects of type Tracker.Grads are not callable
