TensorFlow 从零到helloWorld
目錄
1.git安裝與使用
? ? ?1.1 git安裝
? ? ?1.2 修改git bash默認路徑
? ? ?1.3 git常用操作
2.環境搭建
? 2.1 tensorflow安裝
? 2.2 CUDA安裝
? 2.3 CuDNN安裝
3.測試
? ? ?3.1 helloword測試
? ? ?3.2 簡單線性回歸測試
?
1.git安裝與使用
1.1 git安裝
? ? ?1、從Git官網下載一個Git安裝包,官網地址為:http://git-scm.com/downloads;
? ? ?2、一鍵安裝,環境變量會自己配置好
1.2 修改git bash默認路徑
1. 開始菜單下找到Git Bash 快捷方式
2. 選中Git Bash圖標,右鍵,選中“屬性”?
3. 去掉--cd-to-home,修改“起始位置”為自定義的git 本地倉庫的路徑,如:F:\git_code
1.3 git常用操作
? ? ? 1. 創建新倉庫:創建文件夾,進入文件夾,執行git init 命令
? ? ? 2. 檢出倉庫 :git clone username@host:/path/to/repository
? ? ? 3. 從遠程下載 1) git remote add origin git@github.com:demonxian3/hellowrold.git #關聯本地和遠程倉庫
? ? ? ? ? ? ? ? ? ? ? ? ? ? ?2) git pull origin master #從遠程把新變化拉下來
? ? ? 4. 本地上傳? ? 1) git add your_resource #從本地倉庫增加,結果會保存到本機緩存里
? ? ? ? ? ? ? ? ? ? ? ? ? ? ?2) git commit –m? ? “注釋”? ? ? ? ? ? ? ? ? ? ? ? ? #提交本機緩存的內容到本機HEAD里面
? ? ? ? ? ? ? ? ? ? ? ? ? ? ?3)git push origin master ? ?#把本地倉庫提交到遠程倉庫 origin代表關聯的遠程倉庫
2.環境搭建
2.1 tensorflow安裝
1.pip install tensorflow?
2.2 安裝CUDA(是顯卡廠商NVIDIA推出的運算平臺)
?1.打開鏈接https://developer.nvidia.com/cuda-toolkit-archive 找對應的版本下載 可以下local版(1.4G) 或者network? ? 版 比較小
? 2.安裝后 檢查環境變量 C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin
2.3. 安裝cuDNN(是用于深度神經網絡的GPU加速庫)
? 1.下載https://developer.nvidia.com/rdp/cudnn-download
? 2.解壓配置環境變量C:\Program Files\NVIDIA GPU Computing Toolkit\cudnn-9.0-windows10-x64-v7\cuda\bin
3.測試
?3.1 helloword測試
1.跑helloworld 發現警告 Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
解釋:1)為了提升CPU計算速度的。若你有支持cuda的GPU,則可以忽略這個問題,因為安裝SSE4.1, SSE4.2, AVX, AVX2, FMA, 僅僅提升CPU的運算速度(大概有3倍)
解決辦法:
1)忽視警告,并屏蔽警告
開頭輸入如下:
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
2)進 tensorflow 官網,從源碼安裝。
2.代碼
''' HelloWorld example using TensorFlow library.Author: Aymeric Damien Project: https://github.com/aymericdamien/TensorFlow-Examples/ '''from __future__ import print_functionimport tensorflow as tf# Simple hello world using TensorFlow# Create a Constant op # The op is added as a node to the default graph. # # The value returned by the constructor represents the output # of the Constant op. hello = tf.constant('Hello, TensorFlow!')# Start tf session sess = tf.Session()# Run the op print(sess.run(hello))??3.2 簡單線性回歸測試
''' @author :Eric-chen @contact:809512722@qq.com @time :2018/4/14 18:09 @desc :簡單線性回歸 ''' import tensorflow as tf import numpy as np import osos.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'#create data x_data=np.random.rand(100).astype(np.float32) y_data=0.1*x_data+0.3#create tensorflow structure start Weights=tf.Variable(tf.random_uniform([1],-2.0,2.0)) biases=tf.Variable(tf.zeros([1]))y=Weights*x_data+biases loss=tf.reduce_mean(tf.square(y-y_data))optimizer=tf.train.GradientDescentOptimizer(0.4) train=optimizer.minimize(loss)init=tf.global_variables_initializer() #create tensorflow structure endsess=tf.Session() #Very important sess.run(init) for step in range(2000):sess.run(train)if step%20 ==0:print(step,sess.run(Weights),sess.run(biases))
參考資料:
1.Windows下修改Git Bash 默認路徑
2.Git服務搭建及github使用教程
3.CPU、GPU、CUDA,CuDNN 簡介
轉載于:https://www.cnblogs.com/jycjy/p/8836152.html
總結
以上是生活随笔為你收集整理的TensorFlow 从零到helloWorld的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 关于JAVA并发编程你需要知道的——硬件
- 下一篇: 2013年上半年 中级数据库工程师