tensorflow mac安裝

最近風聲比較緊,google各類連不上,在受限的網絡環境裏邊各類不成功,鬱悶至極。tensorflow在mac上安裝各類不成功,查找各類資料找到一個脫網的安裝方法。本人沒用過python,照貓畫虎,備忘紀錄以下: 配置:mac 10.10系統,系統安裝有pip。python

安裝: 1. 安裝virtualenv 用pip命令來安裝 vmac$ sudo pip install --upgrade virtualenv 2. 安裝好後建立一個工做目錄,我直接在home裏建立了個文件夾. vmac$ virtualenv --system-site-packages ~/tensorflow 3. 而後進入目錄激活沙箱 vmac$ cd ~/tensorflow vmac$ source bin/activate (tensorflow) vmac$ 4. 下載tensorflow http://pan.baidu.com/s/1ntjaMnf 密碼:sznb 把下載下來的tensorflow-0.5.0-py2-none-any.whl文件放到~/tensorflow目錄裏. 進入沙箱後,執行命令來安裝tensorflow在沙箱中. (tensorflow) vmac$ pip install --upgrade tensorflow-0.5.0-py2-none-any.whl網絡

5. 建立個myfirst.py文件 測試一下。
      vmac$ python myfirst.py
import tensorflow as tf
import numpy as np

# Create 100 phony x, y data points in NumPy, y = x * 0.1 + 0.3
x_data = np.random.rand(100).astype(np.float32)
y_data = x_data * 0.1 + 0.3

# Try to find values for W and b that compute y_data = W * x_data + b
# (We know that W should be 0.1 and b 0.3, but Tensorflow will
# figure that out for us.)
W = tf.Variable(tf.random_uniform([1], -1.0, 1.0))
b = tf.Variable(tf.zeros([1]))
y = W * x_data + b

# Minimize the mean squared errors.
loss = tf.reduce_mean(tf.square(y - y_data))
optimizer = tf.train.GradientDescentOptimizer(0.5)
train = optimizer.minimize(loss)

# Before starting, initialize the variables.  We will 'run' this first.
init = tf.initialize_all_variables()

# Launch the graph.
sess = tf.Session()
sess.run(init)

# Fit the line.
for step in range(201):
    sess.run(train)
    if step % 20 == 0:
        print(step, sess.run(W), sess.run(b))

# Learns best fit is W: [0.1], b: [0.3]
相關文章
相關標籤/搜索