R语言Tensorflow安装

R语言Tensorflow安装

引言

今天看到了阿丘图尼·斯里·克里希纳·拉奥著作的一本深度学习书,在R里面用到了Tensorflow.。虽然网上有很多博客分享Tensorflow安装教程,但是好像对我都不是太管用。
本人将自己按照过程中的报错均已记录,大家可以参考一下。

安装过程

本人在安装R语言中的Tensorflow之前,电脑已经安装了python以及Tensorflow

下载Tensorflow,keras,reticulate:

> devtools::install_github("rstudio/tensorflow")
> devtools::install_github("rstudio/keras")
> install.packages('reticulate')
> library(tensorflow)
> tf$constant("Hello, TensorFlow!")  # 测试

报错提示要安装Miniconda,选择Y

安装完成之后收到报错:

错误: Python module tensorflow was not found.

Detected Python configuration:

Miniconda的下载地址为:C:/Users/用户名/AppData/Local/r-miniconda/envs/r-reticulate/python.exe
Rstudio选择下载的python解释器

RstudioTools选项中选择Global options,选择python,点击Select,点击Miniconda的下载地址选项。

测试tensorflow能否成功运行:

> tf$constant("Hello, TensorFlow!")

报错

Error: Installation of TensorFlow not found

解决

> install_tensorflow()

继续报错(具体内容忘了),大概是

You should call install_tensorflow()/install_keras() only in a fresh R session that has not yet initialized Keras and TensorFlow (this is to avoid DLL in use errors during installation)

重启RGui

> library(tensorflow)
> library(keras)
> library(reticulate)
> install_tensorflow() # 等了一会,具体时间忘了;下面为运行结果
Installing collected packages: tensorboard-plugin-wit, pyasn1, libclang, flatbuffers, zipp, wrapt, wheel, urllib3, typing-extensions, 
termcolor, tensorflow-io-gcs-filesystem, tensorflow-estimator, tensorboard-data-server, six, setuptools, rsa, pyasn1-modules, protobuf, packaging, oauthlib, numpy, MarkupSafe, 
keras, idna, grpcio, gast, charset-normalizer, certifi, cachetools, absl-py, werkzeug, requests, opt-einsum, importlib-metadata, h5py, google-pasta, google-auth, astunparse, requests-oauthlib, markdown, google-auth-oauthlib, tensorboard, tensorflow-intel, 
tensorflowSuccessfully installed MarkupSafe-2.1.2 absl-py-1.4.0 astunparse-1.6.3 cachetools-5.3.0 certifi-2022.12.7 charset-normalizer-3.1.0 flatbuffers-23.3.3 
gast-0.4.0 google-auth-2.16.2 google-auth-oauthlib-0.4.6 google-pasta-0.2.0 grpcio-1.51.3 h5py-3.8.0 idna-3.4 importlib-metadata-6.0.0 keras-2.11.0 libclang-15.0.6.1 markdown-3.4.1 numpy-1.24.2 oauthlib-3.2.2 opt-einsum-3.3.0 packaging-23.0 protobuf-
3.19.6 pyasn1-0.4.8 pyasn1-modules-0.2.8 requests-2.28.2 requests-oauthlib-1.3.1 rsa-4.9 setuptools-67.6.0 six-1.16.0 tensorboard-2.11.2 tensorboard-data-server-0.6.1 tensorboard-plugin-wit-1.8.1 tensorflow-2.11.0 tensorflow-estimator-2.11.0 tensorflow-intel-2.11.0 tensorflow-io-gcs-filesystem-0.31.0 termcolor-2.2.0 typing-extensions-4.5.0 urllib3-1.26.15 werkzeug-2.2.3 wheel-0.38.4 wrapt-1.15.0 zipp-3.15.0
Installation complete.

> tf$constant("Hello, TensorFlow!") # 正常运行(TensorFlow)
tf.Tensor(b'Hello, TensorFlow!', shape=(), dtype=string)
> mnist <- dataset_mnist() # 正常运行(keras)
Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/mnist.npz11490434/11490434 [==============================] - 3s 0us/step

以上就是整个TensorFlow,Keras的安装过程,希望我的经历对大家有所帮助。

  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

麻利麻利哄吧

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值