apache / mxnet

Lightweight, Portable, Flexible Distributed/Mobile Deep Learning with Dynamic, Mutation-aware Dataflow Dep Scheduler; for Python, R, Julia, Scala, Go, Javascript and more
https://mxnet.apache.org
Apache License 2.0
20.78k stars 6.79k forks source link

predict error in MXFeedForwardModel logistc regression #14933

Open scotty3005 opened 5 years ago

scotty3005 commented 5 years ago

Description

Trying to get predictions for a simple logistic regression model I geet the error posted in the relative section. I am working with R on ArchLinux.

Environment info (Required)

R version 3.5.3 (2019-03-11) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Arch Linux

Matrix products: default BLAS: /usr/lib/libopenblasp-r0.3.5.so LAPACK: /usr/lib/liblapack.so.3.8.0

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

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

other attached packages: [1] mxnet_1.5.0

loaded via a namespace (and not attached): [1] Rcpp_1.0.1 plyr_1.8.4 pillar_1.3.1 compiler_3.5.3
[5] RColorBrewer_1.1-2 influenceR_0.1.0 viridis_0.5.1 tools_3.5.3
[9] digest_0.6.18 jsonlite_1.6 viridisLite_0.3.0 tibble_2.1.1
[13] gtable_0.2.0 rgexf_0.15.3 pkgconfig_2.0.2 rlang_0.3.4
[17] igraph_1.2.4.1 rstudioapi_0.10 gridExtra_2.3 downloader_0.4
[21] DiagrammeR_1.0.1 dplyr_0.8.0.1 stringr_1.4.0 htmlwidgets_1.3
[25] hms_0.4.2 grid_3.5.3 tidyselect_0.2.5 glue_1.3.1
[29] R6_2.4.0 Rook_1.1-1 XML_3.98-1.16 readr_1.3.1
[33] purrr_0.3.2 tidyr_0.8.3 ggplot2_3.0.0 magrittr_1.5
[37] codetools_0.2-16 scales_1.0.0 htmltools_0.3.6 assertthat_0.2.1
[41] colorspace_1.3-2 brew_1.0-6 stringi_1.4.3 visNetwork_2.0.6
[45] lazyeval_0.2.2 munsell_0.5.0 crayon_1.3.4

Build info (Required if built from source)

Compiler: gcc

MXNet commit hash: b22ee951ae45f7d34b9ae79433f318db5b6bc5ac

Build config:

ifndef CC export CC = gcc endif ifndef CXX export CXX = g++ endif ifndef NVCC export NVCC = nvcc endif DEV = 0 DEBUG = 0 USE_SIGNAL_HANDLER = ADD_LDFLAGS = ADD_CFLAGS = E_CUDA = 0 USE_CUDA_PATH = NONE ENABLE_CUDA_RTC = 1 USE_CUDNN = 0 USE_NVTX = 0 USE_NCCL = 0 USE_NCCL_PATH = NONE USE_OPENCV = 1 USE_OPENCV_INC_PATH = NONE USE_OPENCV_LIB_PATH = NONE USE_LIBJPEG_TURBO = 0 USE_LIBJPEG_TURBO_PATH = NONE USE_OPENMP = 1 USE_MKLDNN = USE_NNPACK = 0 UNAME_S := $(shell uname -s) ifeq ($(UNAME_S), Darwin) USE_BLAS = apple else USE_BLAS = atlas endif USE_LAPACK = 1 USE_LAPACK_PATH = USE_INTEL_PATH = NONE ifeq ($(USE_BLAS), mkl) USE_STATIC_MKL = 1 else USE_STATIC_MKL = NONE endif ARCH := $(shell uname -a) ifneq (,$(filter $(ARCH), armv6l armv7l powerpc64le ppc64le aarch64)) USE_SSE=0 USE_F16C=0 else USE_SSE=1 endif USE_F16C = USE_DIST_KVSTORE = 0 USE_HDFS = 0 LIBJVM=$(JAVA_HOME)/jre/lib/amd64/server USE_S3 = 0 USE_OPERATOR_TUNING = 1 USE_GPERFTOOLS = 0 USE_GPERFTOOLS_PATH = USE_GPERFTOOLS_STATIC = USE_JEMALLOC = 1 USE_JEMALLOC_PATH = USE_JEMALLOC_STATIC = EXTRA_OPERATORS = USE_CPP_PACKAGE = 0 USE_INT64_TENSOR_SIZE = 0

Error Message:

Error in symbol$infer.shape(list(...)) : Error in operator logisticregressionoutput0: [17:10:24] include/mxnet/./tuple.h:202: Check failed: i >= 0 && i < ndim(): index = 0 must be in range [0, -1) Stack trace: [bt] (0) /home/filippo/R/x86_64-pc-linux-gnu-library/3.5/mxnet/libs/libmxnet.so(dmlc::LogMessageFatal::~LogMessageFatal()+0x43) [0x7fd298e1d563] [bt] (1) /home/filippo/R/x86_64-pc-linux-gnu-library/3.5/mxnet/libs/libmxnet.so(mxnet::op::RegressionOpShape(nnvm::NodeAttrs const&, std::vector<mxnet::TShape, std::allocator >, std::vector<mxnet::TShape, std::allocator >)+0x621) [0x7fd29b2f9b91] [bt] (2) /home/filippo/R/x86_64-pc-linux-gnu-library/3.5/mxnet/libs/libmxnet.so(+0x24ddd09) [0x7fd29ad21d09] [bt] (3) /home/filippo/R/x86_64-pc-linux-gnu-library/3.5/mxnet/libs/libmxnet.so(mxnet::exec::InferShape(nnvm::Graph&&, std::vector<mxnet::TShape, std::allocator >&&, std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)+0x1677) [0x

Minimum reproducible example

library(mxnet)

X0 = matrix(rnorm(2000, -10), ncol=2) X1 = matrix(rnorm(2000, 10), ncol=2) X = rbind(X0, X1) Y = c(rep(0, 1000), rep(1, 1000))

ii = sample(1:nrow(X)) X = X[ii,] Y = Y[ii]

mdl = mx.symbol.Variable('data') mdl = mx.symbol.FullyConnected(mdl, num_hidden=1) mdl = mx.symbol.LogisticRegressionOutput(mdl)

mdl = mx.model.FeedForward.create( mdl, X = X, y=Y, array.batch.size=100, num.round=100,

eval.data=list(data = X, label = Y),

eval.metric = mx.metric.logloss,
array.layout = 'rowmajor'

)

predict(mdl, X, array.layout='rowmajor')

vrakesh commented 5 years ago

@mxnet-label-bot add [R]

krzjoa commented 5 years ago

I've encountered very similar problem when trying to run linear regression example.

Environment

R version 3.6.1 (2019-07-05) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 18.04.2 LTS

Matrix products: default BLAS: /usr/local/lib/R/lib/libRblas.so LAPACK: /usr/lib/x86_64-linux-gnu/openblas/liblapack.so.3

locale: [1] LC_CTYPE=pl_PL.UTF-8 LC_NUMERIC=C LC_TIME=pl_PL.UTF-8 LC_COLLATE=pl_PL.UTF-8 LC_MONETARY=pl_PL.UTF-8
[6] LC_MESSAGES=pl_PL.UTF-8 LC_PAPER=pl_PL.UTF-8 LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=pl_PL.UTF-8 LC_IDENTIFICATION=C

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

other attached packages: [1] mxnet_1.5.0

Code to reproduce

library(mxnet) data(BostonHousing, package="mlbench")

train.ind = seq(1, 506, 3) train.x = data.matrix(BostonHousing[train.ind, -14]) train.y = BostonHousing[train.ind, 14] test.x = data.matrix(BostonHousing[-train.ind, -14]) test.y = BostonHousing[-train.ind, 14]

data <- mx.symbol.Variable("data") fc1 <- mx.symbol.FullyConnected(data, num_hidden=1) lro <- mx.symbol.LinearRegressionOutput(fc1)

mx.set.seed(0) model <- mx.model.FeedForward.create( lro, X=train.x, y=train.y, eval.data=list(data=test.x, label=test.y), ctx=mx.cpu(), num.round=10, array.batch.size=20, learning.rate=2e-6, momentum=0.9, eval.metric=mx.metric.rmse, array.layout='rowmajor')

preds = predict(model, test.x) or preds = predict(model, test.x, array.layout='rowmajor')

Result

Error in operator linearregressionoutput0: [01:26:19] include/mxnet/./tuple.h:202: Check failed: i >= 0 && i < ndim(): index = 0 must be in range [0, -1) Stack trace: [bt] (0) /home/krzysztof/R/x86_64-pc-linux-gnu-library/3.6/mxnet/libs/libmxnet.so(dmlc::LogMessageFatal::~LogMessageFatal()+0x43) [0x7fa2cb597583] [bt] (1) /home/krzysztof/R/x86_64-pc-linux-gnu-library/3.6/mxnet/libs/libmxnet.so(mxnet::op::RegressionOpShape(nnvm::NodeAttrs const&, std::vector<mxnet::TShape, std::allocator >, std::vector<mxnet::TShape, std::allocator >)+0x5e1) [0x7fa2ce537e81] [bt] (2) /home/krzysztof/R/x86_64-pc-linux-gnu-library/3.6/mxnet/libs/libmxnet.so(+0x391d29b) [0x7fa2ce8b429b] [bt] (3) /home/krzysztof/R/x86_64-pc-linux-gnu-library/3.6/mxnet/libs/libmxnet.so(mxnet::exec::InferShape(nnvm::Graph&&, std::vector<mxnet::TShape, std::allocator >&&, std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)+0x15cd