# Problem with error reporting in Mocha

**URL:** <https://discourse.julialang.org/t/problem-with-error-reporting-in-mocha/9958>\
**Category:** Machine Learning\
**Created:** [March 25, 2018, 10:24am UTC](https://discourse.julialang.org/t/problem-with-error-reporting-in-mocha/9958 "2018-03-25T10:24:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alejandro](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@Alejandro](https://discourse.julialang.org/u/Alejandro)\
**Post date:** [March 25, 2018, 10:24am UTC](https://discourse.julialang.org/t/problem-with-error-reporting-in-mocha/9958/1 "2018-03-25T10:24:21Z")

</div>

Hello. My name is Alejandro, nice to meet you all. On to business…

I am a total Machine Learning novice beyond the theoretical aspect though now it seems I need to get to work in some applications if I am to actually make use of it. After deciding to settle for Mocha as the package to use going forward I decided to get my toes wet with a tutorial, which is what led me to Diego Acuña’s multi-perceptron one, which he uses to approximate a function ([link here](http://www.diegoacuna.me/multi-layer-perceptron-for-regression-in-julia-using-the-mocha-framework/)). I’ve followed it to the letter but I ran into this problem when executing:

 ![Selection_299](https://global.discourse-cdn.com/julialang/original/3X/c/a/cac82659b0c69d041509462b692e5eb245902357.png)

**Basically that reads:**

```julia
ERROR: LoadError: MethodError: no method matching Mocha.Net(::String, ::Mocha.CPUBackend, ::Array{Any,1})
Closest candidates are:
  Mocha.Net(::AbstractString, ::Mocha.Backend, ::Array{Mocha.Layer,1}) at /home/alejandro/.julia/v0.6/Mocha/src/net.jl:196
  Mocha.Net(::AbstractString, ::T<:Mocha.Backend, ::Array{Mocha.Layer,1}, ::Array{Mocha.LayerState,1}, ::Array{Array{Mocha.Blob,1},1}, ::Array{Array{Mocha.Blob,1},1}, ::Array{Int64,1}, ::Dict{Symbol,Mocha.Blob}, ::Dict{Symbol,Mocha.Blob}) where T<:Mocha.Backend at /home/alejandro/.julia/v0.6/Mocha/src/net.jl:7
Stacktrace:
 [1] include_from_node1(::String) at ./loading.jl:569
 [2] include(::String) at ./sysimg.jl:14
while loading /home/alejandro/Desktop/UNI_SYNC/OTHER/NEURAL NETWORKS/Mocha_tst.jl, in expression starting on line 41

```

Which I don’t understand since the line it refers to is

```julia
net = Net("MLP", backend, [data_layer, common_layers, layer_loss])

```

Which is used to create the actual network. Save for some reference to deprecated stuff, I have had no problem executing each and every line up until that one comes up, and after googling around I can’t find what, exactly, should be wrong because, for all I know, that line should be correct. Even the help document seems to be of no help (no pun intended).

I can provide the whole of the code I’m using though it should be easier to just check on the site in the link I provided. Honestly, I’m stumped 😐.

Thank you so much to anyone that can lend a hand. Cheers.

---

<div class="post-metadata">

**Author:** ![Alejandro](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@Alejandro](https://discourse.julialang.org/u/Alejandro)\
**Post date:** [March 25, 2018, 5:33pm UTC](https://discourse.julialang.org/t/problem-with-error-reporting-in-mocha/9958/2 "2018-03-25T17:33:04Z")

</div>

I should also comment how running Pkg.test(“Mocha”) returns no issues.

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [March 25, 2018, 10:15pm UTC](https://discourse.julialang.org/t/problem-with-error-reporting-in-mocha/9958/3 "2018-03-25T22:15:09Z")

</div>

As the error message says, the `Net` constructor expects an `Array{Mocha.Layer,1}` (also known as a `Vector{Mocha.Layer}`), but you are passing it an `Array{Any}`. So let’s look closer at that input. Your third argument to `Net` is:

```julia
[data_layer, common_layers, layer_loss]

```

where `common_layers` is defined as:

```julia
common_layers = [ip_layer, aggregator]

```

And that’s exactly the problem. Your input, which should be a flat vector of layers, is actually nested. It looks like:

```julia
[data_layer, [ip_layer, aggregator], layer_loss]

```

which isn’t something Mocha.jl understands. The reason this worked in the blog post is that it _used to be_ the case that the `[]` syntax would sort-of-magically flatten its arguments…sometimes? I honestly never fully understood when it did or didn’t, and I was extremely glad to see that semi-magical flattening removed sometime around Julia v0.4.

In your case, you should be able to get a vector of layers by doing:

```julia
vcat(data_layer, common_layers, layer_loss)

```

instead of using `[]`.

---

<div class="post-metadata">

**Author:** ![Alejandro](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@Alejandro](https://discourse.julialang.org/u/Alejandro)\
**Post date:** [March 26, 2018, 2:46am UTC](https://discourse.julialang.org/t/problem-with-error-reporting-in-mocha/9958/4 "2018-03-26T02:46:51Z")

</div>

Thank you so much! That really does help. 👍
