0

I was following this tutorial http://mxnet.io/tutorials/r/fiveMinutesNeuralNetwork.html#regression Everything worked accordingly but when I changed:

fc1 <- mx.symbol.FullyConnected(data, num_hidden=1)

to

fc1 <- mx.symbol.FullyConnected(data, num_hidden=2)

And among the stacks of error logs I thought may be this is the most interesting:

    Error in exec$update.arg.arrays(arg.arrays, match.name, skip.null) : 
    [20:22:59] src/ndarray/ndarray.cc:239: Check failed: from.shape() == to->shape() 
 shape mismatchfrom.shape = (20,) to.shape=(20,2)

How do I diagnose this problem?

Here is the output of sessionInfo():

R version 3.3.3 RC (2017-02-27 r72279)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.5 LTS

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] mlbench_2.1-1 mxnet_0.9.5  

loaded via a namespace (and not attached):
 [1] igraph_1.0.1       Rcpp_0.12.10       rstudioapi_0.6     magrittr_1.5       munsell_0.4.3      colorspace_1.3-2  
 [7] viridisLite_0.2.0  R6_2.2.0           brew_1.0-6         stringr_1.2.0      plyr_1.8.4         dplyr_0.5.0       
[13] visNetwork_1.0.3   Rook_1.1-1         tools_3.3.3        grid_3.3.3         gtable_0.2.0       DBI_0.6           
[19] influenceR_0.1.0   DiagrammeR_0.9.0   htmltools_0.3.5    lazyeval_0.2.0     digest_0.6.12      assertthat_0.1    
[25] tibble_1.2         gridExtra_2.2.1    RColorBrewer_1.1-2 ggplot2_2.2.1      codetools_0.2-8    htmlwidgets_0.8   
[31] viridis_0.4.0      rgexf_0.15.3       stringi_1.1.3      scales_0.4.1       XML_3.98-1.6       jsonlite_1.3   
Ruhshan
  • 121
  • 1
  • 8
  • I could not reproduce your problem on Win 7, R-3.2.3, 64 bit. Please update your post with output of `sessionInfo()` . As preliminary checks you could, 1) try the code in fresh R session 2) if still it fails, try reinstalling package. – Silence Dogood May 01 '17 at 15:49
  • Thanks for your response. Post is updated, running the code in a fresh R session didn't resolved the issue. Let's see what reinstalling has to offer. – Ruhshan May 02 '17 at 10:57

1 Answers1

1

The thing is that below the fc1 <- mx.symbol.FullyConnected(data, num_hidden=1) line, tutorial uses linear regression for the output lro <- mx.symbol.LinearRegressionOutput(fc1).

LinearRegressionOutput is used to compute the l2-loss between it's input symbol and the labels provided to it. It assumes 1 label per example, and passing 2 breaks it. In my case it is a little bit different from your message, maybe because the difference in versions:

Error in symbol$infer.shape(list(...)) : 
  Error in operator linearregressionoutput5: Shape inconsistent, Provided=(20,), inferred shape=(20,2)

Fixing of this depends of what exactly you want to achieve. If you are solving classification task and want to receive probabilities for both classes, then you need to use Softmax:

fc1 <- mx.symbol.FullyConnected(data, num_hidden=2)
lro <- mx.symbol.SoftmaxOutput(fc1)
Sergei
  • 1,617
  • 15
  • 31