JuliaML / LossFunctions.jl

Julia package of loss functions for machine learning.
https://juliaml.github.io/LossFunctions.jl/stable
Other
148 stars 34 forks source link

MethodError: objects of type L2DistLoss are not callable #138

Closed ShuhuaGao closed 2 years ago

ShuhuaGao commented 3 years ago

When following the get started guide, I encountered the error below:

julia> using LossFunctions

julia> loss = L2DistLoss()
L2DistLoss()

julia> loss(1, 0.5f0)
ERROR: MethodError: objects of type L2DistLoss are not callable
Stacktrace:
 [1] top-level scope
   @ REPL[6]:1

version:

barucden commented 3 years ago

It seems that the loss types are not callable now. Is it intentional?

Meanwhile, you can make it callable

julia> using LossFunctions

julia> (l::Loss)(targets, outputs) = value(l, targets, outputs)

julia> loss = L2DistLoss()
LPDistLoss{2}()

julia> loss(1, 0.5f0)
0.25f0
juliohm commented 2 years ago

The functional form works fine with vectors as arguments loss([1,2,3], [4,5,6])