The code given below used to work fine in older versions of mxnet (older than 1.2.0). In version 1.3.0, it seems data.csv is loaded, but label.csv is skipped.
### sessionInfo()
R version 3.5.0 (2018-04-23)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] mxnet_1.3.0
loaded via a namespace (and not attached):
[1] Rcpp_0.12.16 pillar_1.2.2 compiler_3.5.0 RColorBrewer_1.1-2 influenceR_0.1.0 plyr_1.8.4
[7] bindr_0.1.1 viridis_0.5.1 tools_3.5.0 digest_0.6.15 jsonlite_1.5 viridisLite_0.3.0
[13] tibble_1.4.2 gtable_0.2.0 rgexf_0.15.3 pkgconfig_2.0.1 rlang_0.2.0 igraph_1.2.1
[19] rstudioapi_0.7 yaml_2.1.19 bindrcpp_0.2.2 gridExtra_2.3 downloader_0.4 DiagrammeR_1.0.0
[25] dplyr_0.7.4 stringr_1.3.1 htmlwidgets_1.2 hms_0.4.2 grid_3.5.0 glue_1.2.0
[31] R6_2.2.2 Rook_1.1-1 XML_3.98-1.11 readr_1.1.1 purrr_0.2.4 tidyr_0.8.0
[37] ggplot2_2.2.1 magrittr_1.5 codetools_0.2-15 scales_0.5.0 htmltools_0.3.6 assertthat_0.2.0
[43] colorspace_1.3-2 brew_1.0-6 stringi_1.2.2 visNetwork_2.0.3 lazyeval_0.2.1 munsell_0.4.3
https://github.com/apache/incubator-mxnet/tree/master/R-package
cran <- getOption("repos")
cran["dmlc"] <- "https://apache-mxnet.s3-accelerate.dualstack.amazonaws.com/R/CRAN/"
options(repos = cran)
install.packages("mxnet")
Error in symbol$infer.shape(list(...)) :
Error in operator lro: Shape inconsistent, Provided=[1], inferred shape=[1,1,3,3]
batch_size = 1
train_iter <- mx.io.CSVIter(
data.csv = "./matty_inv/A.csv", data.shape = c(3,3,1),
label.csv = "./matty_inv/A.csv", label.shape = c(3, 3, 1),
batch.size = batch_size
)
data <- mx.symbol.Variable('data')
label <- mx.symbol.Variable('label')
conv_1 <- mx.symbol.Convolution(data= data, kernel = c(1,1), num_filter = 4, name="conv_1")
conv_act_1 <- mx.symbol.Activation(data= conv_1, act_type = "relu", name="conv_act_1")
flat <- mx.symbol.flatten(data = conv_act_1, name="flatten")
fcl_1 <- mx.symbol.FullyConnected(data = flat, num_hidden = 9, name="fc_1")
fcl_2 <- mx.symbol.reshape(fcl_1, shape=c(3,3, 1, batch_size))
NN_Model <- mx.symbol.LinearRegressionOutput(data=fcl_2 , label=label, name="lro")
mx.set.seed(99)
autoencoder <- mx.model.FeedForward.create(
NN_Model, X=train_iter, initializer = mx.init.uniform(0.01),
ctx=mx.cpu(), num.round=n.rounds, array.batch.size=batch_size,
learning.rate=8e-3, array.layout = "rowmajor",
eval.metric = mx.metric.rmse, optimizer = "adam",
verbose = TRUE)
@mxnet-label-bot [R, Bug, Data-loading]
Hi @some-guy1
Could you please follow CSVIterator example mentioned over here https://mxnet.incubator.apache.org/tutorials/r/CustomIterator.html. Over here , it assumes label to be a part of the input csv file. This is the specification for csviter API
https://mxnet.apache.org/api/python/io/io.html#mxnet.io.CSVIter
@some-guy1 How did you install the package? I suspect it's a corrupt build you're have. I'm running on 1.3.0 (GPU build on Windows) and the following did work fine:
library(mxnet)
train_iter <- mx.io.CSVIter(
data_csv = "train-data.csv", data.shape = c(2),
label_csv = "train-label.csv", label.shape = c(1),
batch_size = 2
)
train_iter$reset()
train_iter$iter.next()
train_iter$value()
train-data.csv contains two columns while train-label.csv contains a single column.
@ankkhedia the csviter API describes using two different files for data csv and label csv.
@jeremiedb I just copied and pasted the following into RStudio:
cran <- getOption("repos")
cran["dmlc"] <- "https://apache-mxnet.s3-accelerate.dualstack.amazonaws.com/R/CRAN/"
options(repos = cran)
install.packages("mxnet")
Have you tried a label csv with more than a single column? It appears that csv iter is ONLY reading the first column of the csv file even though I said the shape was c(3,3,1)
I tried the following with a label.csv having 6 columns and it returns proper array of shape (3,2,1). Note that batch size is ignored in defining the shape of data and label.
train_iter <- mx.io.CSVIter(
data_csv = "train-data.csv", data.shape = c(2),
label_csv = "train-label.csv", label.shape = c(3, 2),
batch_size = 1
)
@some-guy1 can you please share a small snapshot of the data file you are trying to read - ./matty_inv/A.csv

Can you confirm whether the following is working:
cran <- getOption("repos")
cran["dmlc"] <- "https://apache-mxnet.s3-accelerate.dualstack.amazonaws.com/R/CRAN/"
options(repos = cran)
install.packages("mxnet")
library(data.table)
library(mxnet)
data <- matrix(rnorm(9*5), ncol = 9)
fwrite(x = as.data.table(data), file = "data.csv", col.names = F)
labels <- matrix(rnorm(9*5), ncol = 9)
fwrite(x = as.data.table(data), file = "label.csv", col.names = F)
iter <- mx.io.CSVIter(data_csv = "data.csv",
data_shape = c(9),
label_csv = "label.csv",
label_shape = c(3,1,3),
batch.size = 2)
iter$reset()
iter$iter.next()
iter$value()
This has been run on Windows 10 and R 3.5.1 and worked fine.
From the error message provided symbol$infer.shape(list(...)), issue seems more related to the network definition.
Ok this is confusing living heck out of me. I ran your code above and iter$value() results in the dimensions I would expect. Hence, this appears correct.
BUT, I tried again to simply run only my code below
train_iter <- mx.io.CSVIter(
data_csv = "A.csv", data_shape = c(3, 3, 1),
label_csv = "A.csv", label_shape = c(3, 3, 1),
batch_size = 1
)
train_iter$reset()
train_iter$iter.next()
train_iter$value()
and I still only get one value in the label. I am expecting $label to be identical to $data
$label
[1] 1.373546
Now instead if I run:
train_iter <- mx.io.CSVIter(
data_csv = "A.csv", data_shape = c(3, 3, 1),
label_csv = "A.csv", label_shape = c(3, 1, 3),
batch_size = 1
)
train_iter$reset()
train_iter$iter.next()
train_iter$value()
I get
$`data`
, , 1, 1
[,1] [,2] [,3]
[1,] 1.1643714 2.689276 2.152658
[2,] 0.8696243 1.527834 1.233204
[3,] 2.1957829 2.738622 1.815747
$label
, , 1, 1
[,1]
[1,] 1.1643714
[2,] 0.8696243
[3,] 2.1957829
, , 2, 1
[,1]
[1,] 2.689276
[2,] 1.527834
[3,] 2.738622
, , 3, 1
[,1]
[1,] 2.152658
[2,] 1.233204
[3,] 1.815747
Is it possible that the label axis is rotated relative to the data axis? Are we supposed to transpose the label axis until is matches the data axis?
Interesting! Really looks like a bug when the last label axis is set to 1.
As a quick turnaround, what about dropping the 1 axis for all data and label in the csv.iter and perform a reshape within the model architecture?
Something like:
iter <- mx.io.CSVIter(data_csv = "data.csv",
data_shape = c(3,3),
label_csv = "label.csv",
label_shape = c(3,3),
batch.size = 2)
data <- mx.symbol.Variable("data")
data <- mx.symbol.reshape(data, shape = c(3,1,3,0))
label <- mx.symbol.Variable("label")
label <- mx.symbol.reshape(label, shape = c(3,3,1,0))
...
loss <- mx.symbol.LinearRegressionOutput(data = model, label = label)
Ok so I think we are now moving on to a new problem. I would think the workaround you have posted above should work just fine....but it doesnt. It causes the entire R environment to crash.
I am getting the exact same symptoms when I setup an iterator based on arrays in memory. See the following separate issue I submitted:
@some-guy1 The other issue that you opened was fixed. (#12431) .
Do you think the fix for that fixed this as well ?
@some-guy1 Could you please re-run your script again with the latest MXNet master, the R environment crash issue has been fixed. If you are able to run your script without error then we can close this issue. Thanks!
@some-guy1 I suggest this issue be closed as the snippet used by @jeremiedb loads the labels.
Can you upgrade MXNet R package to V1.4.0 and try it out again and let us know ?
Please feel free to re-open if closed in error.
@Roshrini Can you close this issue ?
As the issue is fixed in v1.4.0, I am closing this issue. Please reopen if you still encounter it or if closed in error. Thanks!