TensorFlow是一個端到端開源機器學習平臺。它擁有一個包含各種工具、庫和社區資源的全面靈活生態系統,可以讓研究人員推動機器學習領域的先進技術的。
準備
安裝 Anaconda
TensorFlow 安裝的前提是系統安裝了 Python 2.5 或更高版本,教程中的例子是以 Python 3.6(Anaconda 3 版)為基礎設計的。為了安裝 TensorFlow,首先確保你已經安裝了 Anaconda。可以從網址(https://www.anaconda.com/distribution/#download-section)中下載並安裝適用於 Windows/macOS 或 Linux 的 Anaconda。
這個是macos的連接,一個是命令行的,一個是GUI的
https://repo.anaconda.com/archive/Anaconda3-2019.10-MacOSX-x86_64.sh
https://repo.anaconda.com/archive/Anaconda3-2019.10-MacOSX-x86_64.pkg
關於安裝 anaconda, 可以參考官方的文檔。
https://docs.anaconda.com/anaconda/install/
---
配置 Anaconda
執行這個命令source ~/.bash_profile, 其實查看這個文件.bash_profile,關鍵的信息export PATH="/opt/anaconda3/bin:$PATH",就是配置anaconda的環境變量。然後執行conda -V
(base) ➜ OpenSource conda -V
conda 4.7.12
安裝
配置 pip 源
這一步可以省略,但是配置為國內的源之後,速度快的飛起來。sudo vi /Users/username/Library/Application Support/pip/pip.conf,然後修改裡面的內容為下面的源。
<code>[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple/
[install]
trusted-host=pypi.tuna.tsinghua.edu.cn/<code>
保存退出即可。
安裝
當前版本只支持 CPU
pip install https://storage.googleapis.com/tensorflow/mac/tensorflow-0.5.0-py2-none-any.whl
或者乾脆直接用pip install tensorflow一樣的。
Hello TensorFlow
這是第一個程序
<code>import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))
# Hello, TensorFlow!/<code>
如果你感興趣可以關注公眾號「chasays」- 程序員匯聚地