顯示具有 TensorFlow 標籤的文章。 顯示所有文章
顯示具有 TensorFlow 標籤的文章。 顯示所有文章

2017年9月2日 星期六

TensorFlow 常數、變數相乘

以下範例可在r1.3版本Tensorflow正確執行,若為其他版本需要再參考API手冊改寫

常數相乘:

import tensorflow as tf

x1 = tf.constant(5)
x2 = tf.constant(6)
result = tf.multiply(x1,x2)
sess = tf.Session()
print(sess.run(result))

變數相乘:

import tensorflow as tf

x1 = tf.Variable([5])
x2 = tf.Variable([6])
result = tf.multiply(x1,x2)
sess = tf.Session()
sess.run(tf.global_variables_initializer())
print(sess.run(result))

windows安裝Tensorflow Object Detection API


以下指令皆在win command line操作

1.
pip3 install pillow
pip3 install lxml
pip3 install jupyter
pip3 install matplotlib

2.
取得protoc程式,可在此網址下載編好的binary https://github.com/google/protobuf/releases/
將下載下來的壓縮包解壓縮,並解壓後的資料夾加入環境變數中


3.
git clone https://github.com/tensorflow/models.git
cd models
protoc object_detection/protos/*.proto --python_out=.

編輯名為 PYTHONPATH 的環境變數(若無,則自行新增),在其內加入剛clone下來的model路徑與model/slim路徑

4.
測試:
python object_detection/builders/model_builder_test.py
若出現OK代表設定成功

win10安裝TensorFlow-GPU

到Python 官網下載並安裝 python 3.5

pip3 install --upgrade tensorflow-gpu

更新nvidia driver

下載cuda toolkit,在安裝時僅選擇安裝cuda選項

下載cudnn 5.1 for cuda8.0與cudnn 6 for cuda8.0,分別解壓縮至.../cuda/cudnn_v5, .../cuda/cudnn_v6資料夾放入C槽,將.../cuda/cudnn_v5/bin, .../cuda/cudnn_v6/bin分別加入至環境變數

測試:
python
import tensorflow as tf
hello = tf.constant('Hello TensorFlow!')
sess = tf.Session()
print(sess.run(hello))