引言
今天看到了阿丘图尼·斯里·克里希纳·拉奥
著作的一本深度学习书,在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解释器
:
在
Rstudio
Tools
选项中选择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
的安装过程,希望我的经历对大家有所帮助。