0
我正在嘗試使用MXNetR構建前饋神經網絡。我的輸入是一個6380行和180列的數據框。我的訓練和測試輸出是一維向量,每個元素有319個元素。運行MXNetR時與數據形狀相關的錯誤
我運行模型的批量大小設置爲1,輸出層的神經元數量設置爲319.因此,對於每個批次,我預計會得到一個包含319個元素的向量。我的目標是最大限度地減少我的損失函數,這是我的預測輸出向量和實際輸出向量之間的相關性。
下面是我的代碼:
# Define the input data
data <- mx.symbol.Variable("data")
# Define the first fully connected layer
fc1 <- mx.symbol.FullyConnected(data, num_hidden = 100)
act.fun <- mx.symbol.Activation(fc1, act_type = "relu") # create a hidden layer with Rectified Linear Unit as its activation function.
output <<- mx.symbol.FullyConnected(act.fun, num_hidden = 319)
# Customize loss function
label <- mx.symbol.Variable("label")
lro <-
mx.symbol.MakeLoss(mx.symbol.Correlation(mx.symbol.reshape(output
,shape = (1,319)),label))
model <- mx.model.FeedForward.create(symbol=lro, X=train.x,
y=train.y,
eval.data = list(data = test.x,
label = test.y),
num.round=5000,
array.batch.size=1,
optimizer = "adam",
learning.rate = 0.0003,
eval.metric = mx.metric.rmse,
epoch.end.callback =
mx.callback.log.train.metric(20, logger))
這裏是錯誤,當我運行上面的代碼:
[15:49:28] /home/cgagnon/src/q5/mxnet/dmlc-core/include/dmlc/./logging.h:304: [15:49:28] src/operator/./correlation-inl.h:176: Check failed: dshape1.ndim() == 4U (2 vs. 4) data should be a 4D tensor
Stack trace returned 10 entries:
[bt] (0) /usr/lib64/R/library/mxnet/libs/libmxnet.so(_ZN4dmlc15LogMessageFatalD1Ev+0x29) [0x7f725a8528b9]
[bt] (1) /usr/lib64/R/library/mxnet/libs/libmxnet.so(_ZNK5mxnet2op15CorrelationProp10InferShapeEPSt6vectorIN4nnvm6TShapeESaIS4_EES7_S7_+0x2a2) [0x7f725b4a8222]
[bt] (2) /usr/lib64/R/library/mxnet/libs/libmxnet.so(+0xd461f9) [0x7f725b3241f9]
[bt] (3) /usr/lib64/R/library/mxnet/libs/libmxnet.so(+0x116630f) [0x7f725b74430f]
[bt] (4) /usr/lib64/R/library/mxnet/libs/libmxnet.so(+0x1167bb2) [0x7f725b745bb2]
[bt] (5) /usr/lib64/R/library/mxnet/libs/libmxnet.so(_ZN4nnvm11ApplyPassesENS_5GraphERKSt6vectorISsSaISsEE+0x501) [0x7f725b761481]
[bt] (6) /usr/lib64/R/library/mxnet/libs/libmxnet.so(_ZN4nnvm9ApplyPassENS_5GraphERKSs+0x8e) [0x7f725b699f2e]
[bt] (7) /usr/lib64/R/library/mxnet/libs/libmxnet.so(_ZN4nnvm4pass10InferShapeENS_5GraphESt6vectorINS_6TShapeESaIS3_EESs+0x240) [0x7f725b69c520]
[bt] (8) /usr/lib64/R/library/mxnet/libs/libmxnet.so(MXSymbolInferShape+0x281) [0x7f725b6959a1]
[bt] (9) /usr/lib64/R/library/mxnet/libs/mxnet.so(_ZNK5mxnet1R6Symbol10InferShapeERKN4Rcpp6VectorILi19ENS2_15PreserveStorageEEE+0x6b9) [0x7f724cef6739]
此刻,我無能,我應該如何解決這個錯誤。我一直在尋找一種方法來重塑我的數據集,使它們成爲四維張量但找不到任何。我不想爲我的問題找到明確的解決方案,但對於如何解決此錯誤的任何建議將不勝感激。
我按照你的建議改變了我的代碼,但仍然出現同樣的錯誤。出於某些隱私原因,我無法與您分享我的數據集,但我相信錯誤在於數據集的維度,而不是內容。 – nnguyen24