gpt4 book ai didi

r - mxnet 中 LSTM RNN 出现错误(R 环境)

转载 作者:行者123 更新时间:2023-11-30 09:51:50 26 4
gpt4 key购买 nike

我正在尝试使用 R 中的 mxnet 设置 LSTM RNN,但是,在尝试训练我的网络时,我收到此错误,并且 R 始终向我显示 fatal error :“[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 中 LSTM RNN 出现错误(R 环境),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43712101/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com