unofficial mirror of help-guix@gnu.org 
 help / color / mirror / Atom feed
From: Simon Tournier <zimon.toutoune@gmail.com>
To: help-guix@gnu.org
Cc: Ricardo Wurmus <rekado@elephly.net>,
	QUENTIN Samuel <samuel.quentin@aphp.fr>
Subject: how to use r-keras?
Date: Fri, 29 Mar 2024 15:28:49 +0100	[thread overview]
Message-ID: <87y1a15cym.fsf@gmail.com> (raw)

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


             reply	other threads:[~2024-03-29 14:29 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-29 14:28 Simon Tournier [this message]
2024-03-29 23:27 ` how to use r-keras? Ricardo Wurmus
2024-05-06 17:11   ` Simon Tournier
2024-05-08 10:11     ` Ricardo Wurmus
2024-05-08 12:34       ` Simon Tournier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87y1a15cym.fsf@gmail.com \
    --to=zimon.toutoune@gmail.com \
    --cc=help-guix@gnu.org \
    --cc=rekado@elephly.net \
    --cc=samuel.quentin@aphp.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).