Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't get Flux (v0.10.3) working for Custom Loss function #1153

Closed
compleathorseplayer opened this issue Apr 29, 2020 · 1 comment
Closed

Comments

@compleathorseplayer
Copy link

I have a very simple problem I am trying to solve using Flux 0.10.3 using methods
which worked with the 0.9.0 version of Flux but which fail now.

xin is a 39K by 50 input matrix (rows are observations, columns are variables)
yout is a 39K by 1 outcome variable.

I run it including a step to verify that the loss function works for the dataset:

julia> model=Chain(Dense(50,1,sigmoid))
Chain(Dense(50, 1, σ))

julia> loss1(x,y)=mean(-(model(x).*y)')
loss1 (generic function with 2 methods)

julia> loss1(x::Tuple)=loss1(x[1],x[2])
loss1 (generic function with 2 methods)

julia> evalcb = () -> @show(loss1((xin',yout'))) #note transposition for compatibility
#63 (generic function with 1 method)

julia> dataset = [(xin',yout'),(xin',yout')];

julia> println(loss1(dataset[1]))
0.0016364615651065868

All of the above seems fine, but when I try to run Flux:

julia> Flux.train!(loss1,params(model),dataset,ADAM(),cb = throttle(evalcb, 5))
ERROR: MethodError: no method matching *(::Dense{typeof(σ),Array{Float32,2},Array{Float32,1}}, ::Float64)
Closest...

Perhaps this is only an issue having to do with change of convention
and calling syntax with the upgrade?

In any case, I would be very grateful for any help.

Actually, it has been noted elsewhere that the more recent (0.10.x) versions of Flux are not
backwards compatible with previous, but I cannot seem to find
any documentation explaining the changes in usage required on the user side.

[I had previously resolved such issues by downgrading to the 0.9.0 version
but had inadvertently included Flux in a general package update to resolve another issue
recently and now find that downgrading to 0.9.0 is broken so I am 'stuck' with the current one]

@ToucheSir
Copy link
Member

I just tried this MWE on 0.12.4 and didn't encounter any issues. Feel free to comment with an updated version (including dummy data) if you're still running into this @compleathorseplayer, but otherwise I think it's safe to close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants