sdobber / FluxArchitectures.jl

Complex neural network examples for Flux.jl
MIT License
123 stars 15 forks source link

How can LSTnet output a 2 dims times Array? #34

Closed hxfcalf closed 2 years ago

hxfcalf commented 2 years ago

Hi, I'm trying to use LSTNet for weather elements forecast.They are 2 dims times mat for a weather station. When I use LSTNet, It out :

the ["PRS", "TEM", "RHU", "U", "V", "PRE_1h", "GST", "lat", "lon", "RHO", "ARED", "AGREEN", "ABLUE"] 1/3 ┌ Warning: Size mismatch in loss function! In future this will be an error. In Flux <= 0.12 broadcasting accepts this, but may not give sensible results │ summary(ŷ) = "1×25 Matrix{Float32}" │ summary(y) = "13×25 Matrix{Float32}"

Could you give me some advice? Thank you.

sdobber commented 2 years ago

Currently, LSTnet only supports one output dimension. To change this right now, you can dev FluxArchitctures in Julia and edit this line: Change

    AL = Chain(a -> a[:,end,1,:], Dense(in, 1, identity; init=initW, bias=bias))

to

    AL = Chain(a -> a[:,end,1,:], Dense(in, outdim, identity; init=initW, bias=bias))

where you replace outdim with the desired number of output dimensions.

The error message you get comes from the fact that the dimensions of the training data and model output don't match. With x your input, model the NN model and y your training data, make sure that the size of model(x) and y are the same when using standard loss functions; otherwise make sure that your loss function does the right thing. This can be a source of weird errors when the calculations go through even though they don't make sense.

hxfcalf commented 2 years ago

Hi,sdobber: I change to : RD = Chain(Dense(2 * recurlayersize, out, identity)) AL = Chain(a -> a[:,end,1,:], Dense(in, out, identity; init=initW, bias=bias)) It can work now. Many thanks!

sdobber commented 2 years ago

Sorry, I overlooked the RD part - good you found it! Happy to help!