ry tensorflow在r中的virtualenv_install中的错误

发布于 2025-01-24 11:17:03 字数 1517 浏览 0 评论 0原文

我正在尝试使用Rstudio的Keras库来培训模型。

library(keras)
N <- 100
x <- runif(N, -2, 3)
# Build a Gompertz function with some noise
a <- 10 # ceiling parameter
b <- 0 # horizontal shift parameter
c <- 2 # growth rate parameter
y <- a*exp(-exp(b - c*x)) + rnorm(N, mean=0, sd= a/10)
plot(x,y)
# format data in a way model.fit() would like it
x <- as.matrix(x)
y <- as.matrix(y)
# sequence along x for later prediction
xnew <- as.matrix(seq(from=min(x), to=max(x), length.out=1000))
# Build and compile simple model
model <- keras_model_sequential() |>
layer_dense(units=32, activation="relu", input_shape=1) |>
layer_dense(units=16, activation = "relu") |>
layer_dense(units=1, activation="linear")

此时我有一个错误

 错误:找不到Python模块Tensorflow.keras。

检测到的Python配置:
 

我发现了一个类似的问题在这里

library(keras)
library(tensorflow)
install_tensorflow()
install_keras()

我有一个错误:

virtualenv_install中的错误 ignore_installed = pip_ignore_installed,:'/usr/local/bin'存在 但不是虚拟环境

我在Python 3.9中安装了Tensorflow和Keras。这是我的pip3冻结输出:

”在此处输入图像说明”

I am trying to train a model using keras library in RStudio.

library(keras)
N <- 100
x <- runif(N, -2, 3)
# Build a Gompertz function with some noise
a <- 10 # ceiling parameter
b <- 0 # horizontal shift parameter
c <- 2 # growth rate parameter
y <- a*exp(-exp(b - c*x)) + rnorm(N, mean=0, sd= a/10)
plot(x,y)
# format data in a way model.fit() would like it
x <- as.matrix(x)
y <- as.matrix(y)
# sequence along x for later prediction
xnew <- as.matrix(seq(from=min(x), to=max(x), length.out=1000))
# Build and compile simple model
model <- keras_model_sequential() |>
layer_dense(units=32, activation="relu", input_shape=1) |>
layer_dense(units=16, activation = "relu") |>
layer_dense(units=1, activation="linear")

at this point I got an error

Error: Python module tensorflow.keras was not found.

Detected Python configuration:

I found a similar issue here and tried to

library(keras)
library(tensorflow)
install_tensorflow()
install_keras()

But I got this error:

Error in virtualenv_install(envname = envname, packages = packages,
ignore_installed = pip_ignore_installed, : '/usr/local/bin' exists
but is not a virtual environment

I have tensorflow and keras installed in my python 3.9. Here is my pip3 freeze output:

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心舞飞扬 2025-01-31 11:17:03

通过在A Fresh R Session 中运行以下操作来解决许多安装问题(您可以使用CTRL+Shift+F10重新启动RSTUDIO的R):

# install the development version of packages, in case the
# issue is already fixed but not on CRAN yet.
install.packages("remotes")
remotes::install_github(sprintf("rstudio/%s", c("reticulate", "tensorflow", "keras")))
reticulate::miniconda_uninstall() # start with a blank slate
reticulate::install_miniconda()
keras::install_keras()

测试以查看安装是否成功。

tensorflow::as_tensor("Hello World")

如果以上片段成功,并且您看到了tf.tensor(b'hello world',shape =(),dtype = string) ,那么您已经成功安装了TensorFlow!
如果没有,请在

Many installation issues are resolved by running the following in a fresh R session (you can restart R in Rstudio with Ctrl+Shift+F10) :

# install the development version of packages, in case the
# issue is already fixed but not on CRAN yet.
install.packages("remotes")
remotes::install_github(sprintf("rstudio/%s", c("reticulate", "tensorflow", "keras")))
reticulate::miniconda_uninstall() # start with a blank slate
reticulate::install_miniconda()
keras::install_keras()

Test to see if installation was successful.

tensorflow::as_tensor("Hello World")

If the above snippet succeeded and you saw something like tf.Tensor(b'Hello World', shape=(), dtype=string), then you've successfully installed Tensorflow!
If not, please file an issue at https://github.com/rstudio/tensorflow/issues

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文