# MethodError: objects of type Float64 are not callable

**URL:** <https://discourse.julialang.org/t/methoderror-objects-of-type-float64-are-not-callable/81876>\
**Category:** Machine Learning\
**Tags:** flux\
**Created:** [May 29, 2022, 5:38pm UTC](https://discourse.julialang.org/t/methoderror-objects-of-type-float64-are-not-callable/81876 "2022-05-29T17:38:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hupdup](https://avatars.discourse-cdn.com/v4/letter/h/7ba0ec/32.png) [@Hupdup](https://discourse.julialang.org/u/Hupdup)\
**Post date:** [May 29, 2022, 5:38pm UTC](https://discourse.julialang.org/t/methoderror-objects-of-type-float64-are-not-callable/81876/1 "2022-05-29T17:38:58Z")

</div>

Hi,  
when I want to update the weights of my main\_network, I always get this ERROR:  
MethodError: objects of type Float64 are not callable

 ![grafik](https://global.discourse-cdn.com/julialang/original/3X/2/0/208a0402de4f5730ace2619b44b8b6c8704af7dd.png)

The Output is:  
-24.429102722601773  
Float32[-0.019576067, 0.08515469, -0.026341796]  
-0.026341796  
so I do get Floats as a result for x and y, which I use to calculate the loss

but for line 137 I get the error…do you know, what I should change?

ERROR: MethodError: objects of type Float64 are not callable  
Stacktrace:  
[1] macro expansion  
@ C:\Users\aetan.julia\packages\Zygote\TaBlo\src\compiler\interface2.jl:0 [inlined]  
[2] \_pullback(::Zygote.Context, ::Float64)  
@ Zygote C:\Users\aetan.julia\packages\Zygote\TaBlo\src\compiler\interface2.jl:9  
[3] \_pullback  
@ c:\Users\aetan\Desktop\DQN\_Shems\DQN\_Test.jl:137 [inlined]  
[4] \_pullback(::Zygote.Context, ::var"#34#35"{Float64})  
@ Zygote C:\Users\aetan.julia\packages\Zygote\TaBlo\src\compiler\interface2.jl:0  
[5] pullback(f::Function, ps::Params)  
@ Zygote C:\Users\aetan.julia\packages\Zygote\TaBlo\src\compiler\interface.jl:343  
[6] gradient(f::Function, args::Params)  
@ Zygote C:\Users\aetan.julia\packages\Zygote\TaBlo\src\compiler\interface.jl:75  
[7] replay(; rng\_rpl::Int64)  
@ Main c:\Users\aetan\Desktop\DQN\_Shems\DQN\_Test.jl:137

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [May 29, 2022, 6:01pm UTC](https://discourse.julialang.org/t/methoderror-objects-of-type-float64-are-not-callable/81876/2 "2022-05-29T18:01:22Z")

</div>

Look at line 135. There you define

```julia
loss = 0.5 * (y - x)^2

```

which presumably is a `Float64`. Then, on line 137, you create an anonymous function that takes zero inputs:

```julia
() -> loss()

```

But `loss` is a number, you cannot call it, as the error message says.

---

<div class="post-metadata">

**Author:** ![ToucheSir](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/touchesir/32/14411_2.png) [@ToucheSir](https://discourse.julialang.org/u/ToucheSir)\
**Post date:** [May 29, 2022, 6:04pm UTC](https://discourse.julialang.org/t/methoderror-objects-of-type-float64-are-not-callable/81876/3 "2022-05-29T18:04:11Z")

</div>

If you print out `typeof(loss)`, you will see that it is a `Float64` and not a function as you would expect. Thus calling it fails because you can’t call a floating point number 😉

More broadly, Zygote requires that _all_ the code between the first use of the input `x` and the final calculation of `loss` needs to be inside that callback you pass to `gradient`. That means at least line 125-135 and possibly higher up in your file. I would highly, highly recommend you read through [Basics · Flux](https://fluxml.ai/Flux.jl/stable/models/basics/) and/or [Overview · Flux](https://fluxml.ai/Flux.jl/stable/models/overview/) to get an understanding of how the library works before continuing.
