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

MethodError: no method matching flatten(::Array{Float32,4}) #1630

Closed
paritosh5feb opened this issue Jun 25, 2021 · 1 comment
Closed

MethodError: no method matching flatten(::Array{Float32,4}) #1630

paritosh5feb opened this issue Jun 25, 2021 · 1 comment

Comments

@paritosh5feb
Copy link

I implemented this CNN for Image Segmentation. I am getting the following issue.
`function leNet5()
return Chain(
convBlock(101,202),
MeanPool((5,5)),
convBlock(202,404),
MeanPool((5,5)),
flatten,
Dense(20,40),
Dense(40,80),
Dense(80,101))
end

m = leNet5()
p = params(m)
loss(x, y) = crossentropy(m(x), y)
opt = ADAM(0.001, (0.9, 0.8))
epochs = 10
@epochs epochs Flux.train!(loss, p, train_data, opt, cb = () -> println("training"))`

The Image Data is in the format WHCN.

Error:-

MethodError: no method matching flatten(::Array{Float32,4})
Closest candidates are:
flatten(::AbstractDataFrame, ::Union{Colon, Regex, AbstractString, Signed, Symbol, Unsigned, AbstractArray{T,1} where T, All, Between, Cols, InvertedIndex}) at /home/jupyterlab/.julia/packages/DataFrames/nxjiD/src/abstractdataframe/abstractdataframe.jl:2126

Stacktrace:
[1] macro expansion at /home/jupyterlab/.julia/packages/Zygote/1GXzF/src/compiler/interface2.jl:0 [inlined]
[2] _pullback(::Zygote.Context, ::typeof(flatten), ::Array{Float32,4}) at /home/jupyterlab/.julia/packages/Zygote/1GXzF/src/compiler/interface2.jl:13
[3] applychain at /home/jupyterlab/.julia/packages/Flux/NpkMm/src/layers/basic.jl:30 [inlined]
[4] _pullback(::Zygote.Context, ::typeof(Flux.applychain), ::Tuple{typeof(flatten),Dense{typeof(identity),Array{Float32,2},Array{Float32,1}},Dense{typeof(identity),Array{Float32,2},Array{Float32,1}},Dense{typeof(identity),Array{Float32,2},Array{Float32,1}}}, ::Array{Float32,4}) at /home/jupyterlab/.julia/packages/Zygote/1GXzF/src/compiler/interface2.jl:0
[5] applychain at /home/jupyterlab/.julia/packages/Flux/NpkMm/src/layers/basic.jl:30 [inlined]
[6] _pullback(::Zygote.Context, ::typeof(Flux.applychain), ::Tuple{MeanPool{2,4},typeof(flatten),Dense{typeof(identity),Array{Float32,2},Array{Float32,1}},Dense{typeof(identity),Array{Float32,2},Array{Float32,1}},Dense{typeof(identity),Array{Float32,2},Array{Float32,1}}}, ::Array{Float32,4}) at /home/jupyterlab/.julia/packages/Zygote/1GXzF/src/compiler/interface2.jl:0
[7] applychain at /home/jupyterlab/.julia/packages/Flux/NpkMm/src/layers/basic.jl:30 [inlined]
[8] _pullback(::Zygote.Context, ::typeof(Flux.applychain), ::Tuple{Chain{Tuple{Conv{2,2,typeof(identity),Array{Float32,4},Array{Float32,1}},getfield(Main, Symbol("##101#102"))}},MeanPool{2,4},typeof(flatten),Dense{typeof(identity),Array{Float32,2},Array{Float32,1}},Dense{typeof(identity),Array{Float32,2},Array{Float32,1}},Dense{typeof(identity),Array{Float32,2},Array{Float32,1}}}, ::Array{Float32,4}) at /home/jupyterlab/.julia/packages/Zygote/1GXzF/src/compiler/interface2.jl:0
[9] applychain at /home/jupyterlab/.julia/packages/Flux/NpkMm/src/layers/basic.jl:30 [inlined]
[10] _pullback(::Zygote.Context, ::typeof(Flux.applychain), ::Tuple{MeanPool{2,4},Chain{Tuple{Conv{2,2,typeof(identity),Array{Float32,4},Array{Float32,1}},getfield(Main, Symbol("##101#102"))}},MeanPool{2,4},typeof(flatten),Dense{typeof(identity),Array{Float32,2},Array{Float32,1}},Dense{typeof(identity),Array{Float32,2},Array{Float32,1}},Dense{typeof(identity),Array{Float32,2},Array{Float32,1}}}, ::Array{Float32,4}) at /home/jupyterlab/.julia/packages/Zygote/1GXzF/src/compiler/interface2.jl:0
[11] applychain at /home/jupyterlab/.julia/packages/Flux/NpkMm/src/layers/basic.jl:30 [inlined]
[12] _pullback(::Zygote.Context, ::typeof(Flux.applychain), ::Tuple{Chain{Tuple{Conv{2,2,typeof(identity),Array{Float32,4},Array{Float32,1}},getfield(Main, Symbol("##101#102"))}},MeanPool{2,4},Chain{Tuple{Conv{2,2,typeof(identity),Array{Float32,4},Array{Float32,1}},getfield(Main, Symbol("##101#102"))}},MeanPool{2,4},typeof(flatten),Dense{typeof(identity),Array{Float32,2},Array{Float32,1}},Dense{typeof(identity),Array{Float32,2},Array{Float32,1}},Dense{typeof(identity),Array{Float32,2},Array{Float32,1}}}, ::Array{Float32,4}) at /home/jupyterlab/.julia/packages/Zygote/1GXzF/src/compiler/interface2.jl:0
[13] Chain at /home/jupyterlab/.julia/packages/Flux/NpkMm/src/layers/basic.jl:32 [inlined]
[14] _pullback(::Zygote.Context, ::Chain{Tuple{Chain{Tuple{Conv{2,2,typeof(identity),Array{Float32,4},Array{Float32,1}},getfield(Main, Symbol("##101#102"))}},MeanPool{2,4},Chain{Tuple{Conv{2,2,typeof(identity),Array{Float32,4},Array{Float32,1}},getfield(Main, Symbol("##101#102"))}},MeanPool{2,4},typeof(flatten),Dense{typeof(identity),Array{Float32,2},Array{Float32,1}},Dense{typeof(identity),Array{Float32,2},Array{Float32,1}},Dense{typeof(identity),Array{Float32,2},Array{Float32,1}}}}, ::Array{Float32,4}) at /home/jupyterlab/.julia/packages/Zygote/1GXzF/src/compiler/interface2.jl:0
[15] loss at ./In[41]:4 [inlined]
[16] _pullback(::Zygote.Context, ::typeof(loss), ::Array{Float32,4}, ::Array{Float32,4}) at /home/jupyterlab/.julia/packages/Zygote/1GXzF/src/compiler/interface2.jl:0
[17] adjoint(::Zygote.Context, ::typeof(Core._apply), ::Function, ::Tuple{Array{Float32,4},Array{Float32,4}}) at /home/jupyterlab/.julia/packages/Zygote/1GXzF/src/lib/lib.jl:168
[18] _pullback(::Zygote.Context, ::getfield(Flux.Optimise, Symbol("##17#25")){typeof(loss)}) at /home/jupyterlab/.julia/packages/ZygoteRules/OjfTt/src/adjoint.jl:57
[19] pullback(::Function, ::Params) at /home/jupyterlab/.julia/packages/Zygote/1GXzF/src/compiler/interface.jl:172
[20] gradient(::Function, ::Params) at /home/jupyterlab/.julia/packages/Zygote/1GXzF/src/compiler/interface.jl:53
[21] macro expansion at /home/jupyterlab/.julia/packages/Flux/NpkMm/src/optimise/train.jl:87 [inlined]
[22] macro expansion at /home/jupyterlab/.julia/packages/Juno/n6wyj/src/progress.jl:134 [inlined]
[23] #train!#12(::getfield(Main, Symbol("##121#125")), ::Function, ::typeof(loss), ::Params, ::Flux.Data.DataLoader, ::ADAM) at /home/jupyterlab/.julia/packages/Flux/NpkMm/src/optimise/train.jl:80
[24] (::getfield(Flux.Optimise, Symbol("#kw##train!")))(::NamedTuple{(:cb,),Tuple{getfield(Main, Symbol("##121#125"))}}, ::typeof(Flux.Optimise.train!), ::Function, ::Params, ::Flux.Data.DataLoader, ::ADAM) at ./none:0
[25] top-level scope at /home/jupyterlab/.julia/packages/Flux/NpkMm/src/optimise/train.jl:120
[26] top-level scope at /home/jupyterlab/.julia/packages/Juno/n6wyj/src/progress.jl:134
[27] top-level scope at In[64]:1

@DhairyaLGandhi
Copy link
Member

It would be more helpful to check the documentation for flatten. You also probably only need a reshape in this case. I'm closing this issue for now, but feel free to ask usage questions on the julia lang slack on the #helpdesk channel. Thanks!

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

2 participants