我有来自this Github的代码,我从中下载了rprop.py
(弹性反向传播优化器代码)。我在具有Keras / tf后端的R / RStudio中引用了它,如下所示:
library(keras)
library(reticulate)
...
source_python("C:\\mini\\envs\\aiml3\\Lib\\site-packages\\tensorflow_core\\python\\keras\\optimizer_v2\\rprop.py")
myopt = RProp(name="rprop")
model <- keras_model_sequential() %>%
layer_dense(units = 2, activation = "sigmoid", input_shape = c(2)) %>%
layer_dense(units = 1, activation = "sigmoid")
model %>% compile(
optimizer = myopt,
loss = "binary_crossentropy",
metrics = c("accuracy")
)
并且我的模型可以编译,但是当我像这样训练模型时,会出现错误。
history <- model %>% fit(
trainee, #1000 x 2 binary matrix
y, #1000 x 1 binary matrix
epochs = 3,
batch_size = 1800,
verbose = 1,
)
Train on 2000 samples
Epoch 1/3
1800/2000 [==========================>...] - ETA: 0s Error in py_call_impl(callable, dots$args, dots$keywords) :
AttributeError: 'RProp' object has no attribute '_create_slots'
Detailed traceback:
File "C:\mini\envs\aiml3\lib\site-packages\tensorflow_core\python\keras\engine\training.py", line 728, in fit
use_multiprocessing=use_multiprocessing)
File "C:\mini\envs\aiml3\lib\site-packages\tensorflow_core\python\keras\engine\training_v2.py", line 324, in fit
total_epochs=epochs)
File "C:\mini\envs\aiml3\lib\site-packages\tensorflow_core\python\keras\engine\training_v2.py", line 123, in run_one_epoch
batch_outs = execution_function(iterator)
File "C:\mini\envs\aiml3\lib\site-packages\tensorflow_core\python\keras\engine\training_v2_utils.py", line 86, in execution_function
distributed_function(input_fn))
File "C:\mini\envs\aiml3\lib\site-packages\tensorflow_core\python\eager\def_function.py", line 457, in __call__
result = self._call(*args, **kwds)
File "C:\mini\envs\aiml3\lib\site-packages\tensorflow_core\python\eager\def_function.py", line 503, in _call
如果我将批次大小增加到2000,除AttributeError: 'Tensor' object has no attribute '_datatype_enum'
以外,我会得到相同的错误
请帮忙,我的论文即将到期,我不知道为什么我的模型不起作用!谢谢。
另一方面,我使用RProp的原因是因为1)它的速度和2)它是我以前使用的neuralnet
软件包所使用的。使用adam
或rmsprop
可以吗?