這篇文章主要講解了“怎么在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 這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關知識點的文章,歡迎關注!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。