0

I am new in applying the neural network models, I am using linux Ubuntu , and the versions that are installed are:

tf_config()
TensorFlow v2.16.1 (~/miniconda3/lib/python3.12/site-packages/tensorflow)
Python v3.12 (~/miniconda3/bin/python3.12)

so I am doing the examples that are represented in the reference "Deep Learning with R, second edition" in chapter 10, all the steps were good, so when I get to the code of :

model %>%

compile(optimizer = "rmsprop",
loss = "mse",
metrics = "mae")

it gives me the follwoing error:

Error in UseMethod("compile") :
método não aplicável para 'compile' aplicado a um objeto de classe "c('keras.src.models.functional.Functional', 'keras.models.functional.Functional', 'keras.src.ops.function.Function', 'keras.ops.function.Function', 'keras.src.models.model.Model', 'keras.models.model.Model', 'keras.src.backend.tensorflow.trainer.TensorFlowTrainer', 'keras.backend.tensorflow.trainer.TensorFlowTrainer', 'keras.src.trainers.trainer.Trainer', 'keras.trainers.trainer.Trainer', 'keras.src.layers.layer.Layer', 'keras.layers.layer.Layer', 'keras.src.backend.tensorflow.layer.TFLayer', 'keras.backend.tensorflow.layer.TFLayer', 'keras.src.backend.tensorflow.trackable.KerasAutoTrackable', 'keras.backend.tensorflow.trackable.KerasAutoTrackable', 'tensorflow.python.trackable.autotrackable.AutoTrackable', 'tensorflow.python.trackable.base.Trackable', 'keras.src.ops.operation.Operation', 'keras.ops.operation.Operation', 'keras.src.saving.keras_saveable.KerasSaveable', 'keras.saving.keras_saveable.KerasSavea

Can someone help to detect where might be the error to solve the problem, thx.

I was trying to build a simple lstm model using Rstudio and the reference "Deep Learning with R, second edition" in chapter 10. The example was going very good, only when I reached to the line that will excute the compile command, it gives error, and I can't know how to fix it.

5
  • Try running your code in Google Colab. Likely you won't have issues with compatibility. Commented Jul 8 at 18:45
  • Perhaps you have loaded both keras and keras3?
    – Axeman
    Commented Jul 8 at 19:19
  • it seems that I did; > is_installed <- function(package_name) { + return(package_name %in% rownames(installed.packages())) + } > is_installed("keras3") [1] TRUE > is_installed("keras") [1] TRUE What should I do in this case? Commented Jul 8 at 19:47
  • They are not compatible. Either use keras or keras3, not both. (They can both be installed, but not both loaded using e.g. library(keras), restart R and only load 1).
    – Axeman
    Commented Jul 8 at 20:52
  • I deleted keras3 and returned to execute the code, and yet the compile is giving me the same error. Commented Jul 8 at 21:19

0

Browse other questions tagged or ask your own question.