Hi, Trying to run “r-keras”, I am a bit puzzled.
--8<---------------cut here---------------start------------->8--- $ guix shell r r-keras -C python-minimal r-reticulate tensorflow --8<---------------cut here---------------end--------------->8--- Well, one needs to know some internals… --8<---------------cut here---------------start------------->8--- $ R R version 4.3.3 (2024-02-29) -- "Angel Food Cake" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-unknown-linux-gnu (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library(keras) --8<---------------cut here---------------end--------------->8--- So far, so good! Let try the tutorial [1]. Then my first “surprise”: --8<---------------cut here---------------start------------->8--- > model <- keras_model_sequential() Would you like to create a default python environment for the reticulate package? (Yes/no/cancel) no --8<---------------cut here---------------end--------------->8--- which leads to this unexpected message: --8<---------------cut here---------------start------------->8--- /gnu/store/134bswprchk6rp3f5pskva3dq0j8gycp-profile/lib/python3.10/site-packages/tensorflow/python/framework/dtypes.py:523: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. _np_qint8 = np.dtype([("qint8", np.int8, 1)]) /gnu/store/134bswprchk6rp3f5pskva3dq0j8gycp-profile/lib/python3.10/site-packages/tensorflow/python/framework/dtypes.py:524: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. _np_quint8 = np.dtype([("quint8", np.uint8, 1)]) /gnu/store/134bswprchk6rp3f5pskva3dq0j8gycp-profile/lib/python3.10/site-packages/tensorflow/python/framework/dtypes.py:525: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. _np_qint16 = np.dtype([("qint16", np.int16, 1)]) /gnu/store/134bswprchk6rp3f5pskva3dq0j8gycp-profile/lib/python3.10/site-packages/tensorflow/python/framework/dtypes.py:526: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. _np_quint16 = np.dtype([("quint16", np.uint16, 1)]) /gnu/store/134bswprchk6rp3f5pskva3dq0j8gycp-profile/lib/python3.10/site-packages/tensorflow/python/framework/dtypes.py:527: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. _np_qint32 = np.dtype([("qint32", np.int32, 1)]) /gnu/store/134bswprchk6rp3f5pskva3dq0j8gycp-profile/lib/python3.10/site-packages/tensorflow/python/framework/dtypes.py:532: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. np_resource = np.dtype([("resource", np.ubyte, 1)]) --8<---------------cut here---------------end--------------->8--- Ok, let create a model: --8<---------------cut here---------------start------------->8--- > model %>% # Adds a densely-connected layer with 64 units to the model: layer_dense(units = 64, activation = 'relu') %>% # Add another: layer_dense(units = 64, activation = 'relu') %>% # Add a softmax layer with 10 output units: layer_dense(units = 10, activation = 'softmax') > + + + + + + + + + > > model %>% compile( optimizer = 'adam', loss = 'categorical_crossentropy', metrics = list('accuracy') ) + + + + > --8<---------------cut here---------------end--------------->8--- So far, so good! Now, let train the model: --8<---------------cut here---------------start------------->8--- > data <- matrix(rnorm(1000 * 32), nrow = 1000, ncol = 32) labels <- matrix(rnorm(1000 * 10), nrow = 1000, ncol = 10) model %>% fit( data, labels, epochs = 10, batch_size = 32 ) > > > + + + + + Error in py_get_attr_impl(x, name, silent) : AttributeError: module 'kerastools' has no attribute 'callback' Run `reticulate::py_last_error()` for details. --8<---------------cut here---------------end--------------->8--- And this error reads: --8<---------------cut here---------------start------------->8--- > reticulate::py_last_error() -- Python Exception Message ---------------------------------------------------- AttributeError: module 'kerastools' has no attribute 'callback' -- R Traceback ----------------------------------------------------------------- x 1. +-model %>% fit(data, labels, epochs = 10, batch_size = 32) 2. +-generics::fit(., data, labels, epochs = 10, batch_size = 32) 3. \-keras:::fit.keras.engine.training.Model(...) 4. \-keras:::normalize_callbacks_with_metrics(...) 5. \-keras:::normalize_callbacks(callbacks) 6. \-base::lapply(...) 7. \-keras (local) FUN(X[[i]], ...) 8. +-base::do.call(tools$callback$RCallback, args) 9. +-tools$callback 10. \-reticulate:::`$.python.builtin.module`(tools, "callback") 11. \-reticulate:::`$.python.builtin.object`(x, name) 12. \-reticulate:::py_get_attr_or_item(x, name, TRUE) 13. \-reticulate::py_get_attr(x, name) 14. \-reticulate:::py_get_attr_impl(x, name, silent) --8<---------------cut here---------------end--------------->8--- Hum? My second surprise. Any idea how to run Keras from R? Cheers, simon 1: https://tensorflow.rstudio.com/guides/keras/basics.html