compile problem

Hi, 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.

This was an error similar to this in an earlier version of keras, which has been fixed now. Can you check if you're using the latest R package release?

Also, you may want to install keras3, the next version of Keras. Many of the examples from the book should continue to work unmodified.

Finally, consider using a virtualenv instead of miniconda - it lets you side-step any incompatibilities between conda and non-conda binaries. This should be all that's needed:

install.packages("keras3")
reticulate::install_python()
keras3::install_keras()

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.