您好,登錄后才能下訂單哦!
這篇文章主要講解了“怎么在mac下安裝tensorflow ”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“怎么在mac下安裝tensorflow ”吧!
安裝: 1. 安裝virtualenv 用pip命令來安裝 vmac$ sudo pip install --upgrade virtualenv 2. 安裝好后創(chuàng)建一個(gè)工作目錄,我直接在home里創(chuàng)建了個(gè)文件夾. vmac$ virtualenv --system-site-packages ~/tensorflow 3. 然后進(jìn)入目錄激活沙箱 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目錄里. 進(jìn)入沙箱后,執(zhí)行命令來安裝tensorflow在沙箱中. (tensorflow) vmac$ pip install --upgrade tensorflow-0.5.0-py2-none-any.whl
5. 創(chuàng)建個(gè)myfirst.py文件 測(cè)試一下。 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 ”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對(duì)怎么在mac下安裝tensorflow 這一問題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。