我正在尝试制作多层Keras RNN模型,如下所示:
ttrainx=as.matrix(data.frame(c1=c(0,2,3,4,5,1,2,3,4,5),c2=c(1,3,4,5,6,1,2,3,4,5),c3=c(0,4,5,6,7,1,2,3,4,5)))
ttrainy=as.matrix(data.frame(y1=c(5,6,7,8,9,1,2,3,4,5),y2=c(6,7,8,9,1,2,3,4,5,5),y3=c(0,1,0,0,0,0,0,0,1,1)))
# Initialize model
#========
model <- keras_model_sequential()
model %>%
layer_masking(mask_value = -1,input_shape = list(NULL,3))
layer_lstm(units = 10,return_sequences = TRUE) %>%
layer_lstm(units = 10,return_sequences = TRUE) %>%
layer_lstm(units = 10,return_sequences = TRUE) %>%
layer_lstm(units = 10) %>%
layer_dropout(rate = 0.5) %>%
layer_dense(units =3, activation = 'linear')
# Try using different optimizers and different optimizer configs
model %>% compile(
loss = 'mse',
optimizer = 'rmsprop',
metrics = c('accuracy')
)
# Train model over four epochs
cat('Train...\n')
model %>% fit(
#x_train, y_train,
ttrainx,ttrainy,
batch_size = 5,
epochs = 30,
#validation_data = list(x_test, y_test)
validation_split = 0.2
)
但是我在模型拟合时遇到了以下异常:
py_call_impl(可调用,dots $ args,dots $ keywords)错误: ValueError:检查输入时出错:预期masking_1_input具有3维,但数组的形状为(10,3)
任何人都可以指出为什么我会遇到例外吗?