我正在尝试通过在R中使用mxnet来设置LSTM RNN,但是,在尝试训练我的网络时,出现此错误,R一直在向我显示致命错误:
“ [[00:36:08] d:\ program files(x86)\ jenkins \ workspace \ mxnet \ mxnet \ src \ operator \ tensor./matrix_op-inl.h:155:不建议使用target_shape。
[00:36:08] d:\ program files(x86)\ jenkins \ workspace \ mxnet \ mxnet \ src \ operator \ tensor./matrix_op-inl.h:155:不建议使用target_shape。
[00:36:08] d:\ program files(x86)\ jenkins \ workspace \ mxnet \ mxnet \ src \ operator \ tensor./matrix_op-inl.h:155:不建议使用target_shape。

这是我的代码:

# install.packages("drat", repos="https://cran.rstudio.com")
# drat:::addRepo("dmlc")
# install.packages("mxnet")

rm(list = ls())
require(mxnet)
require(mlbench)

inputData <- read.table(file.path(getwd(), "Data", "input.csv"),
                     header = TRUE, sep = ",")
inputData$X <- as.Date(inputData$X)
inputData <- na.omit(inputData)

index <- 1:nrow(inputData)*0.8

train.dates <- inputData[index,1]
test.dates <- inputData[-index,1]
inputData[,1] <- NULL

train <- inputData[index,]
test <- inputData[-index,]

train.x <- data.matrix(train[,-ncol(train)])
test.x <- data.matrix(test[,-ncol(test)])

train.y <- train[,ncol(train)]
test.y <- test[,ncol(test)]

get.label <- function(X) {
  label <- array(0, dim=dim(X))
  d <- dim(X)[1]
  w <- dim(X)[2]
  for (i in 0:(w-1)) {
    for (j in 1:d) {
      label[i*d+j] <- X[(i*d+j)%%(w*d)+1]
    }
  }
  return (label)
}

X.train.label <- get.label(t(train.x))
X.val.label <- get.label(t(test.x))

X.train <- list(data=t(train.x), label=X.train.label)
X.val <- list(data=t(test.x), label=X.val.label)

batch.size = 1
seq.len = 32
num.hidden = 16
num.embed = 16
num.lstm.layer = 1
num.round = 1
learning.rate= 0.1
wd=0.00001
clip_gradient=1
update.period = 1

model <- mx.lstm(X.train, X.val,
                 ctx=mx.cpu(),
                 num.round=num.round,
                 update.period=update.period,
                 num.lstm.layer=num.lstm.layer,
                 seq.len=seq.len,
                 num.hidden=num.hidden,
                 num.embed=num.embed,
                 num.label=15,
                 batch.size=batch.size,
                 input.size=15,
                 initializer=mx.init.uniform(0.1),
                 learning.rate=learning.rate,
                 wd=wd,
                 clip_gradient=clip_gradient)


输入数据集由“日期”列,15个要素和目标值组成。
请帮我提前致谢!

最佳答案

您收到的消息是警告,您可以忽略它。真正的问题是形状不匹配。如果我运行您的代码,我将收到:

  [14:06:36] src/ndarray/ndarray.cc:348: Check failed: from.shape() == to->shape() operands shape mismatchfrom.shape = (1,15) to.shape=(1,32)


要解决此问题,请设置seq.len = 15,因为您具有15个功能。如果您更新seq.len并运行您的代码,您将看到培训开始(注意,我也收到与您相同的警告):

[14:08:17] src/operator/tensor/./matrix_op-inl.h:159: Using target_shape will be deprecated.
[14:08:17] src/operator/tensor/./matrix_op-inl.h:159: Using target_shape will be deprecated.
[14:08:17] src/operator/tensor/./matrix_op-inl.h:159: Using target_shape will be deprecated.
Iter [1] Train: Time: 0.263811111450195 sec, NLL=2.71622828266634, Perp=15.1231742012938
Iter [1] Val: NLL=2.51107457406329, Perp=12.3181597260587

关于r - MXNET(R环境)中的LSTM RNN错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43712101/

10-13 00:03