rstudio / tensorflow.rstudio.com

https://tensorflow.rstudio.com
9 stars 12 forks source link

error running the TensorFlow for R tutorials #60

Closed fabarrios closed 1 year ago

fabarrios commented 1 year ago

Following the Tutorials

In the Basic Image Classification tutorial, running step by step. Everything runs well with the model definition:

model <- keras_model_sequential()

I get:

2023-08-09 18:17:13.540599: I metal_plugin/src/device/metal_device.cc:1154] Metal device set to: Apple M2 Pro
2023-08-09 18:17:13.540646: I metal_plugin/src/device/metal_device.cc:296] systemMemory: 32.00 GB
2023-08-09 18:17:13.540655: I metal_plugin/src/device/metal_device.cc:313] maxCacheSize: 10.67 GB
2023-08-09 18:17:13.540796: I tensorflow/core/common_runtime/pluggable_device/pluggable_device_factory.cc:303] Could not identify NUMA node of platform GPU ID 0, defaulting to 0. Your kernel may not have been built with NUMA support.
2023-08-09 18:17:13.541152: I tensorflow/core/common_runtime/pluggable_device/pluggable_device_factory.cc:269] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 0 MB memory) -> physical PluggableDevice (device: 0, name: METAL, pci bus id: <undefined>)

And when I run the designation:

model %>%
     layer_flatten(input_shape = c(28, 28)) %>%
     layer_dense(units = 128, activation = 'relu') %>%
     layer_dense(units = 10, activation = 'softmax')

I get the error:

Error in py_get_attr_impl(x, name, silent) : 
  AttributeError: module 'tensorflow.keras' has no attribute '__version__'
Run `reticulate::py_last_error()` for details.

with the 'reticulate::py_last_error()' I get:
TypeError: 'Sequential' object is not subscriptable

── R Traceback ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
     ▆
  1. └─.rs.environment.isSuspendable()
  2.   ├─base::tryCatch(...)
  3.   │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
  4.   │   └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
  5.   │     └─base (local) doTryCatch(return(expr), name, parentenv, handler)
  6.   └─.rs.environment.isSuspendableImpl(globalenv(), 1L)
  7.     └─.rs.environment.isSuspendableImpl(value[[key]], depth + 1L)
  8.       ├─.rs.environment.isSuspendableImpl(value[[i]], depth + 1L)
  9.       ├─value[[i]]
 10.       └─reticulate:::`[[.python.builtin.object`(value, i)
 11.         └─reticulate:::py_get_attr_or_item(x, name, FALSE)
 12.           └─reticulate::py_get_item(x, name)
 13.             └─reticulate:::py_get_item_impl(x, key, FALSE)
t-kalinowski commented 1 year ago

Hi, this is an error that has been fixed in the development versions of tensorflow and keras. Please run this and try again:

remotes::install_github("rstudio/tensorflow")
remotes::install_github("rstudio/keras")
keras::install_keras()
fabarrios commented 1 year ago

Thank you very much, now it is running