# Implementing RProp in Keras

I have the code from this Github from which I download rprop.py, the resilient backpropagation optimizer code. I reference it in R/RStudio with Keras/tf backend like this:

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")
)


and my model compiles, but when I train the model like so, I get an error.

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


if I increase the batch size to 2000 I get the same error except with AttributeError: 'Tensor' object has no attribute '_datatype_enum'

Please help, my thesis is due soon and I have no idea why my model isn't working! Thank you.

On a side note, the reason I'm using RProp is because of 1) it's speed and 2) it's what is used by the neuralnet package, which I was using previously. Would I be fine using adam or rmsprop?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.