R中的tensorflow得到了"无效的版本规范"

时间:2017-02-28 13:02:01

标签: r tensorflow rstudio

我是新手R-lang,想在mac(OS Sierra 10.12.2)和RStudio(v1.0.136)中执行tensorflow

根据manual,我在下面写了代码。

代码:

if(!require(tensorflow))devtools::install_github("rstudio/tensorflow")
Sys.setenv(TENSORFLOW_PYTHON="/usr/local/bin/python")
library(tensorflow)
sess = tf$Session()

但是我收到了这个错误:

Error: invalid version specification ‘1.11.0.0+4821’

要确认环境,Sys.getenv()得到以下代码。

    __CF_USER_TEXT_ENCODING                    0x1F5:0x1:0xE
    Apple_PubSub_Socket_Render                 /private/tmp/com.apple.launchd.WiLEfbiuX2/Render
    DISPLAY                                    /private/tmp/com.apple.launchd.BkPQx3AwYq/org.macosforge.xquartz:0
    DYLD_FALLBACK_LIBRARY_PATH                 /usr/local/Cellar/r/3.3.2/R.framework/Resources/lib:/Users/XXXXXXXX/lib:/usr/local/lib:/usr/lib::
      EDITOR                                     vi
    GIT_ASKPASS                                rpostback-askpass
    HOME                                       /Users/XXXXXXX
    LANG                                       ja_JP.UTF-8
    LC_CTYPE                                   ja_JP.UTF-8
    LN_S                                       ln -s
    LOGNAME                                    XXXXXXXX
    MAKE                                       make
    PAGER                                      /usr/bin/less
    PATH                                       /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/texbin
    R_BROWSER                                  /usr/bin/open
    R_BZIPCMD                                  /usr/bin/bzip2
    R_DOC_DIR                                  /usr/local/Cellar/r/3.3.2/R.framework/Resources/doc
    R_GZIPCMD                                  /usr/bin/gzip
    R_HOME                                     /usr/local/Cellar/r/3.3.2/R.framework/Resources
    R_INCLUDE_DIR                              /usr/local/Cellar/r/3.3.2/R.framework/Resources/include
    R_LIBS_SITE                                
    R_LIBS_USER                                ~/Library/R/3.3/library
    R_PAPERSIZE                                a4
    R_PDFVIEWER                                /usr/bin/open
    R_PLATFORM                                 x86_64-apple-darwin16.1.0
    R_PRINTCMD                                 lpr
    R_RD4PDF                                   times,inconsolata,hyper
    R_SESSION_TMPDIR                           /var/folders/0w/9nb7gxk17s599b2jw_r3xz2m0000gn/T//RtmpgBwRUK
    R_SHARE_DIR                                /usr/local/Cellar/r/3.3.2/R.framework/Resources/share
    R_SYSTEM_ABI                               osx,gcc,gxx,gfortran,?
    R_TEXI2DVICMD                              /usr/local/opt/texinfo/bin/texi2dvi
    R_UNZIPCMD                                 /usr/bin/unzip
    R_ZIPCMD                                   /usr/bin/zip
    RETICULATE_PYTHON                          /usr/local/bin/python
    RMARKDOWN_MATHJAX_PATH                     /Applications/RStudio.app/Contents/Resources/resources/mathjax-26
    RS_RPOSTBACK_PATH                          /Applications/RStudio.app/Contents/MacOS/rpostback
    RS_SHARED_SECRET                           59cac018-9866-4eaf-947d-6020a5ad7b1a
    RSTUDIO                                    1
    RSTUDIO_PANDOC                             /Applications/RStudio.app/Contents/MacOS/pandoc
    RSTUDIO_SESSION_PORT                       29295
    RSTUDIO_USER_IDENTITY                      XXXXXXXX
    RSTUDIO_WINUTILS                           bin/winutils
    SECURITYSESSIONID                          186a5
    SED                                        /usr/bin/sed
    SHELL                                      /bin/zsh
    SSH_AUTH_SOCK                              /private/tmp/com.apple.launchd.jId37NiWlo/Listeners
    TAR                                        /usr/bin/tar
    TENSORFLOW_PYTHON                          /usr/local/bin/python
    TMPDIR                                     /var/folders/0w/9nb7gxk17s599b2jw_r3xz2m0000gn/T/
      USER                                       XXXXXXXX
    XPC_FLAGS                                  0x0
    XPC_SERVICE_NAME                           0

但是在控制台中的python

Python 2.7.11 (default, Oct 25 2016, 15:42:11)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.38)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> tf.Session()
<tensorflow.python.client.session.Session object at 0x110938fd0>

如果我执行:

pip show tensorflow

得到

    Name: tensorflow
    Version: 0.9.0
    Summary: TensorFlow helps the tensors flow
    Home-page: http://tensorflow.org/
      Author: Google Inc.
    Author-email: opensource@google.com
    License: Apache 2.0
    Location: /Users/XXXXXXXX/.pyenv/versions/2.7.11/envs/tensorflow0.9.0/lib/python2.7/site-packages
    Requires: protobuf, wheel, numpy, six

有没有人有解决方案来删除R?

中的错误

1 个答案:

答案 0 :(得分:0)

通过执行以下步骤,我规避了无效的版本规范错误:

  1. 从conda tensorflow环境启动tensorboard(确保在此环境中具有tensorboard):

    conda activate tensorflow

然后输入张量板命令

  tensorboard --logdir 'logs'

结果表明,我可以在 localhost:6006 中使用tensorboard:

Tensorboard 2.0.0 at http://localhost:6006

  1. 在网络浏览器中输入了地址,并且张量板为空

  2. 然后,在R Studio上运行keras会话,并使用以下命令设置培训历史记录

    callbacks = callback_tensorboard('logs/run_a')

并且,在训练纪元仍在运行的同时,我在Web浏览器中刷新了tensorboard,这迫使从'logs'目录中加载新数据。这样我就得到了训练历史。