網頁

顯示具有 TensorFlow 標籤的文章。 顯示所有文章
顯示具有 TensorFlow 標籤的文章。 顯示所有文章

2020年3月9日 星期一

Mac install tensorflow 2.1.0, Keras 2.3.1, scikit-learn, and RDkit

Tensorflow:
我選擇system安裝,不使用virtual environment

$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
$ export PATH="/usr/local/bin:/usr/local/sbin:$PATH"
$ brew update
$ brew install python
$ sudo pip3 install -U virtualenv
$ pip3 install --user --upgrade tensorflow

如果是python3.7.3版本的話要修改linecache.py

$ sudo vi /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/linecache.py

第48行改成
for mod in list(sys.modules.values()): # for mod in sys.modules.values():

Keras:

$ brew install hdf5
$ brew install graphviz
$ sudo pip3 install pydot (一定要加sudo)
$ vi ~/.bash_profile
export PATH=/usr/local/bin:/usr/local/sbin:~/bin:$PATH
$ source ~/.bash_profile
$ sudo pip3 install keras (一定要加sudo)

scikit-learn:
$ pip3 install -U scikit-learn

RDkit:
$ brew tap rdkit/rdkit
$ brew install rdkit

If you need to have icu4c first in your PATH run:
  echo 'export PATH="/usr/local/opt/icu4c/bin:$PATH"' >> ~/.zshrc
  echo 'export PATH="/usr/local/opt/icu4c/sbin:$PATH"' >> ~/.zshrc

For compilers to find icu4c you may need to set:
  export LDFLAGS="-L/usr/local/opt/icu4c/lib"
  export CPPFLAGS="-I/usr/local/opt/icu4c/include"

==> openblas
openblas is keg-only, which means it was not symlinked into /usr/local,
because macOS provides BLAS and LAPACK in the Accelerate framework.

For compilers to find openblas you may need to set:
  export LDFLAGS="-L/usr/local/opt/openblas/lib"
  export CPPFLAGS="-I/usr/local/opt/openblas/include"

==> rdkit
      You may need to add RDBASE to your environment variables.
      For Bash, put something like this in your $HOME/.bashrc:
        export RDBASE=/usr/local/share/RDKit

參考
https://github.com/rdkit/homebrew-rdkit

Mac執行tensorflow發生RuntimeError: dictionary changed size during iteration

問題:
Homebrew的python3版本是3.7.3
在執行tensorflow時出現以下

.
.
.
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/linecache.py", line 48, in getlines
    for mod in sys.modules.values():

RuntimeError: dictionary changed size during iteration

解決:
$ sudo vi /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/linecache.py

第48行改成
for mod in list(sys.modules.values()): # for mod in sys.modules.values():



參考
http://www.kaierlong.me/blog/post/kaierlong/tensorflow-2.0-%E9%94%99%E8%AF%AF-RuntimeError-dictionary-changed-size-during-iteration

2019年10月27日 星期日

Windows install RDkit Tensorflow Keras

1.安裝RDkit

打開Anaconda3 Prompt (Anaconda3)終端機
$ conda create -c rdkit -n my-rdkit-env rdkit python=3.7
$ conda activate my-rdkit-env

create -c rdkit -n my-rdkit-env意思是在Windows Anaconda3環境裡產生一個名叫my-rdkit-env的環境,因為tensorflow只支援Python3.7,所以在最後還要輸入python=3.7代表在my-rdkit-env環境下是使用python=3.7,接著就可以依序安裝tensorflow跟Keras了!

2.在my-rdkit-env環境下安裝tensorflow2.0
$ conda install tensorflow-gpu=2.0 python=3.7

3.在my-rdkit-env環境下安裝Keras
$ conda install Keras

4.在my-rdkit-env環境下安裝jupyter notebook
$ conda install jupyter

5.安裝CUDA
因為RDkit只支援CUDA 10.0,所以到下面連結下載CUDA 10.0
https://developer.nvidia.com/cuda-toolkit-archiv


2019年5月6日 星期一

Mac Keras+RDKit

因為tensorflow安裝以及RDKit利用Homebrew安裝都是呼叫同一個呼叫/usr/local/bin裡的python3,所以使用這兩個函式庫之前要先輸入

$ which python3

來確認是否呼叫正確位置的python3。不是的話,由於先前安裝RDKit時,有設定"export PATH=/usr/local/bin:/usr/local/sbin:~/bin:$PATH"在~/.bash_profile,因此輸入

$ source ~/.bash_profile

再確認python3是否更改為"/usr/local/bin/python3"


2019年5月4日 星期六

ValueError: Object arrays cannot be loaded when allow_pickle=False

Using TensorFlow backend.
Traceback (most recent call last):
  File "test_keras.py", line 13, in <module>
    (X_train, y_train), (X_test, y_test) = imdb.load_data(num_words=top_words)
  File "/usr/local/lib/python3.6/site-packages/keras/datasets/imdb.py", line 59, in load_data
    x_train, labels_train = f['x_train'], f['y_train']
  File "/usr/local/lib/python3.6/site-packages/numpy/lib/npyio.py", line 262, in __getitem__
    pickle_kwargs=self.pickle_kwargs)
  File "/usr/local/lib/python3.6/site-packages/numpy/lib/format.py", line 692, in read_array
    raise ValueError("Object arrays cannot be loaded when "
ValueError: Object arrays cannot be loaded when allow_pickle=False


numpy版本不符合當前代碼,更新Numpy版本1.16.3,導致加載數據過程中出錯,

$ pip install numpy==1.16.2

參考
https://www.twblogs.net/a/5cc61956bd9eee1ac2ed4944

Xcode version must be specified to use an Apple CROSSTOOL

ERROR: /private/var/tmp/_bazel_yangyan-ling/2ce5cc8600b6d4faf46244230a6eedc1/external/local_config_cc/BUILD:58:5: in apple_cc_toolchain rule @local_config_cc//:cc-compiler-armeabi-v7a: Xcode version must be specified to use an Apple CROSSTOOL. If your Xcode version has changed recently, try: "bazel clean --expunge" to re-run Xcode configuration
ERROR: Analysis of target '//tensorflow/tools/pip_package:build_pip_package' failed; build aborted: Analysis of target '@local_config_cc//:cc-compiler-armeabi-v7a' failed; build aborted
INFO: Elapsed time: 0.242s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (5 packages loaded, 48 targets configured)
    currently loading: tensorflow/core ... (2 packages)

$ bazel clean --expunge
$ sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
$ sudo xcodebuild -license
$ bazel clean --expunge

2019年5月3日 星期五

Executing genrule //tensorflow:python_api_gen failed (Exit 1) bash failed: error executing command /bin/bash -c ...

ERROR: /Users/yangyan-ling/tensorflow/tensorflow/BUILD:541:1: Executing genrule //tensorflow:python_api_gen failed (Exit 1) bash failed: error executing command /bin/bash -c ... (remaining 1 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox
Traceback (most recent call last):
  File "/private/var/tmp/_bazel_yangyan-ling/2ce5cc8600b6d4faf46244230a6eedc1/sandbox/darwin-sandbox/5695/execroot/org_tensorflow/bazel-out/host/bin/tensorflow/tools/api/generator/create_python_api.runfiles/org_tensorflow/tensorflow/tools/api/generator/create_python_api.py", line 27, in <module>
    from tensorflow.python.util import tf_decorator
  File "/private/var/tmp/_bazel_yangyan-ling/2ce5cc8600b6d4faf46244230a6eedc1/sandbox/darwin-sandbox/5695/execroot/org_tensorflow/bazel-out/host/bin/tensorflow/tools/api/generator/create_python_api.runfiles/org_tensorflow/tensorflow/python/__init__.py", line 63, in <module>
    from tensorflow.python.framework.framework_lib import *  # pylint: disable=redefined-builtin
  File "/private/var/tmp/_bazel_yangyan-ling/2ce5cc8600b6d4faf46244230a6eedc1/sandbox/darwin-sandbox/5695/execroot/org_tensorflow/bazel-out/host/bin/tensorflow/tools/api/generator/create_python_api.runfiles/org_tensorflow/tensorflow/python/framework/framework_lib.py", line 52, in <module>
    from tensorflow.python.framework.importer import import_graph_def
  File "/private/var/tmp/_bazel_yangyan-ling/2ce5cc8600b6d4faf46244230a6eedc1/sandbox/darwin-sandbox/5695/execroot/org_tensorflow/bazel-out/host/bin/tensorflow/tools/api/generator/create_python_api.runfiles/org_tensorflow/tensorflow/python/framework/importer.py", line 27, in <module>
    from tensorflow.python.framework import function
  File "/private/var/tmp/_bazel_yangyan-ling/2ce5cc8600b6d4faf46244230a6eedc1/sandbox/darwin-sandbox/5695/execroot/org_tensorflow/bazel-out/host/bin/tensorflow/tools/api/generator/create_python_api.runfiles/org_tensorflow/tensorflow/python/framework/function.py", line 37, in <module>
    from tensorflow.python.ops import variable_scope as vs
  File "/private/var/tmp/_bazel_yangyan-ling/2ce5cc8600b6d4faf46244230a6eedc1/sandbox/darwin-sandbox/5695/execroot/org_tensorflow/bazel-out/host/bin/tensorflow/tools/api/generator/create_python_api.runfiles/org_tensorflow/tensorflow/python/ops/variable_scope.py", line 24, in <module>
    import enum  # pylint: disable=g-bad-import-order
ImportError: No module named enum
Target //tensorflow/tools/pip_package:build_pip_package failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 3067.684s, Critical Path: 183.55s, Remote (0.00% of the time): [queue: 0.00%, setup: 0.00%, process: 0.00%]
INFO: 5694 processes: 5691 darwin-sandbox, 3 local.
FAILED: Build did NOT complete successfully


$ pip install enum34
$ pip uninstall enum


參考
https://github.com/tensorflow/serving/issues/893

Mac install tensorflow-1.9.0+Keras

官方版的安裝對Mac有許多限制,如果不想利用虛擬環境跑TensorFlow的話,以下是安裝流程。

xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

$ sudo xcode-select -s /Applications/Xcode.app/Contents/Developer


參考
https://vyspiansky.github.io/2018/09/28/xcodebuild-requires-xcode/

TensorFlow2.0中文教程

http://bangqu.com/48ce39.html