温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

怎么在mac下安装tensorflow

发布时间:2021-08-12 09:37:35 来源:亿速云 阅读:163 作者:chen 栏目:云计算

这篇文章主要讲解了“怎么在mac下安装tensorflow ”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“怎么在mac下安装tensorflow ”吧!

安装: 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]

感谢各位的阅读,以上就是“怎么在mac下安装tensorflow ”的内容了,经过本文的学习后,相信大家对怎么在mac下安装tensorflow 这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI