MethodError: objects of type Float64 are not callable

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

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

Look at line 135. There you define

loss = 0.5 * (y - x)^2

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

() -> loss()

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

1 Like

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 :wink:

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 and/or Overview · Flux to get an understanding of how the library works before continuing.