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]
相关文章
相关标签/搜索