all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* how to use r-keras?
@ 2024-03-29 14:28 Simon Tournier
  2024-03-29 23:27 ` Ricardo Wurmus
  0 siblings, 1 reply; 5+ messages in thread
From: Simon Tournier @ 2024-03-29 14:28 UTC (permalink / raw)
  To: help-guix; +Cc: Ricardo Wurmus, QUENTIN Samuel

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: how to use r-keras?
  2024-03-29 14:28 how to use r-keras? Simon Tournier
@ 2024-03-29 23:27 ` Ricardo Wurmus
  2024-05-06 17:11   ` Simon Tournier
  0 siblings, 1 reply; 5+ messages in thread
From: Ricardo Wurmus @ 2024-03-29 23:27 UTC (permalink / raw)
  To: Simon Tournier; +Cc: help-guix, QUENTIN Samuel


Simon Tournier <zimon.toutoune@gmail.com> writes:

> Trying to run “r-keras”, I am a bit puzzled.
>
> [2. text/x-verbatim]
> $ guix shell r r-keras -C python-minimal r-reticulate tensorflow

Is this with tensorflow from guix-science?  The old Tensorflow 1.9 in
Guix does not provide Keras.  Only the more recent one in Guix Science
does.

The Python bindings for tensorflow are provided by python-tensorflow.

(I don't know how to use r-keras.)

-- 
Ricardo


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: how to use r-keras?
  2024-03-29 23:27 ` Ricardo Wurmus
@ 2024-05-06 17:11   ` Simon Tournier
  2024-05-08 10:11     ` Ricardo Wurmus
  0 siblings, 1 reply; 5+ messages in thread
From: Simon Tournier @ 2024-05-06 17:11 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: help-guix, QUENTIN Samuel

Hi Ricardo,

On sam., 30 mars 2024 at 00:27, Ricardo Wurmus <rekado@elephly.net> wrote:

>> $ guix shell r r-keras -C python-minimal r-reticulate tensorflow
>
> Is this with tensorflow from guix-science?  The old Tensorflow 1.9 in
> Guix does not provide Keras.  Only the more recent one in Guix Science
> does.

Using Guix 929ddec, it fails as reported previously; using
tensorflow@1.9.0.  Let try with tensorflow@2.13.1.

Well, although I have guix.bordeaux.inria.fr as substitutes, I had to
rebuild tensorflow.  Ouch!

Then I get this:

--8<---------------cut here---------------start------------->8---
$ guix time-machine -C channels.scm -- shell -C r r-keras -C python-minimal r-reticulate tensorflow@2.13.1
simon@lili /tmp [env]$ 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)
> model <- keras_model_sequential()
Would you like to create a default python environment for the reticulate package? (Yes/no/cancel) no
Error: Valid installation of TensorFlow not found.

Python environments searched for 'tensorflow' package:
 /gnu/store/66ncidnhpj2djnik3g6iljzr30k056cy-python-minimal-3.10.7/bin/python3.10

Python exception encountered:
 Traceback (most recent call last):
  File "/gnu/store/sd979h0ckv6fnmwqvlypq91w49q9521k-r-reticulate-1.35.0/site-library/reticulate/python/rpytools/loader.py", line 119, in _find_and_load_hook
    return _run_hook(name, _hook)
  File "/gnu/store/sd979h0ckv6fnmwqvlypq91w49q9521k-r-reticulate-1.35.0/site-library/reticulate/python/rpytools/loader.py", line 93, in _run_hook
    module = hook()
  File "/gnu/store/sd979h0ckv6fnmwqvlypq91w49q9521k-r-reticulate-1.35.0/site-library/reticulate/python/rpytools/loader.py", line 117, in _hook
    return _find_and_load(name, import_)
ModuleNotFoundError: No module named 'tensorflow'


You can install TensorFlow using the install_tensorflow() function.
--8<---------------cut here---------------end--------------->8---

And I guess that’s not better. :-)

Hum, working with Keras needs more love…

Cheers,
simon


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: how to use r-keras?
  2024-05-06 17:11   ` Simon Tournier
@ 2024-05-08 10:11     ` Ricardo Wurmus
  2024-05-08 12:34       ` Simon Tournier
  0 siblings, 1 reply; 5+ messages in thread
From: Ricardo Wurmus @ 2024-05-08 10:11 UTC (permalink / raw)
  To: Simon Tournier; +Cc: help-guix, QUENTIN Samuel

Hi Simon,

> On sam., 30 mars 2024 at 00:27, Ricardo Wurmus <rekado@elephly.net> wrote:
>
>>> $ guix shell r r-keras -C python-minimal r-reticulate tensorflow
>>
>> Is this with tensorflow from guix-science?  The old Tensorflow 1.9 in
>> Guix does not provide Keras.  Only the more recent one in Guix Science
>> does.
>
> Using Guix 929ddec, it fails as reported previously; using
> tensorflow@1.9.0.  Let try with tensorflow@2.13.1.
>
> Well, although I have guix.bordeaux.inria.fr as substitutes, I had to
> rebuild tensorflow.  Ouch!

This appears to be a common problem, but we don't know why.  It's
probably related to the bazel-build-system.  You'll get substitutes only
if you use `--no-grafts'.


> Then I get this:
>
> --8<---------------cut here---------------start------------->8---
> $ guix time-machine -C channels.scm -- shell -C r r-keras -C
> python-minimal r-reticulate tensorflow@2.13.1

You need python-tensorflow (also from guix-science), not just the
tensorflow library.

-- 
Ricardo


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: how to use r-keras?
  2024-05-08 10:11     ` Ricardo Wurmus
@ 2024-05-08 12:34       ` Simon Tournier
  0 siblings, 0 replies; 5+ messages in thread
From: Simon Tournier @ 2024-05-08 12:34 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: help-guix, QUENTIN Samuel

Hi Ricardo,

On mer., 08 mai 2024 at 12:11, Ricardo Wurmus <rekado@elephly.net> wrote:

> This appears to be a common problem, but we don't know why.  It's
> probably related to the bazel-build-system.  You'll get substitutes only
> if you use `--no-grafts'.

Ah, weird… I miss how the build system could impact the content-address.
Another story. :-)


>> Then I get this:
>>
>> --8<---------------cut here---------------start------------->8---
>> $ guix time-machine -C channels.scm -- shell -C r r-keras -C
>> python-minimal r-reticulate tensorflow@2.13.1
>
> You need python-tensorflow (also from guix-science), not just the
> tensorflow library.

Cool!  It just works!

Thank you.

Cheers,
simon


--8<---------------cut here---------------start------------->8---
$ guix time-machine -C channels.scm \
       -- shell -C r r-keras -C python-minimal r-reticulate tensorflow@2.13.1 python-tensorflow

[env]$ 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)
> model <- keras_model_sequential()
Would you like to create a default python environment for the reticulate package? (Yes/no/cancel) no
2024-05-08 12:30:26.110266: I tensorflow/core/util/port.cc:110] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
2024-05-08 12:30:26.137568: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: SSE3 SSE4.1 SSE4.2 AVX AVX2 AVX512F AVX512_VNNI AVX512_BF16 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation.
WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation.
WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation.
WARNING:root:Limited tf.summary API due to missing TensorBoard installation.
WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation.
WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation.
WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation.
> 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')
)
+ + + + > 
> 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
)
> > > + + + + + Epoch 1/10
32/32 [==============================] - 0s 837us/step - loss: -0.2669 - accuracy: 0.1060
32/32 [==============================] - 0s 951us/step - loss: -0.2669 - accuracy: 0.1060
Epoch 2/10
32/32 [==============================] - 0s 743us/step - loss: -0.4499 - accuracy: 0.1120
32/32 [==============================] - 0s 1ms/step - loss: -0.4499 - accuracy: 0.1120  
Epoch 3/10
32/32 [==============================] - 0s 682us/step - loss: -0.6262 - accuracy: 0.1050
32/32 [==============================] - 0s 736us/step - loss: -0.6262 - accuracy: 0.1050
Epoch 4/10
32/32 [==============================] - 0s 643us/step - loss: -0.8110 - accuracy: 0.1150
32/32 [==============================] - 0s 695us/step - loss: -0.8110 - accuracy: 0.1150
Epoch 5/10
32/32 [==============================] - 0s 614us/step - loss: -1.0271 - accuracy: 0.1270
32/32 [==============================] - 0s 659us/step - loss: -1.0271 - accuracy: 0.1270
Epoch 6/10
32/32 [==============================] - 0s 535us/step - loss: -1.1987 - accuracy: 0.1480
32/32 [==============================] - 0s 599us/step - loss: -1.1987 - accuracy: 0.1480
Epoch 7/10
32/32 [==============================] - 0s 637us/step - loss: -1.4685 - accuracy: 0.1230
32/32 [==============================] - 0s 739us/step - loss: -1.4685 - accuracy: 0.1230
Epoch 8/10
32/32 [==============================] - 0s 608us/step - loss: -1.7238 - accuracy: 0.1380
32/32 [==============================] - 0s 654us/step - loss: -1.7238 - accuracy: 0.1380
Epoch 9/10
32/32 [==============================] - 0s 552us/step - loss: -1.9540 - accuracy: 0.1270
32/32 [==============================] - 0s 592us/step - loss: -1.9540 - accuracy: 0.1270
Epoch 10/10
32/32 [==============================] - 0s 705us/step - loss: -2.2367 - accuracy: 0.1160
32/32 [==============================] - 0s 773us/step - loss: -2.2367 - accuracy: 0.1160
> 
--8<---------------cut here---------------end--------------->8---


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-05-08 12:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-29 14:28 how to use r-keras? Simon Tournier
2024-03-29 23:27 ` Ricardo Wurmus
2024-05-06 17:11   ` Simon Tournier
2024-05-08 10:11     ` Ricardo Wurmus
2024-05-08 12:34       ` Simon Tournier

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.