KZKY memo

自分用メモ.

TensorFlow: Getting Started

Basic Usage

Install
  • cuda 7.0 (gpu使いたい場合)
$ wget "http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1404/x86_64/cuda-repo-ubuntu1404_7.0-28_amd64.deb"
$ sudo dpkg -i cuda-repo-ubuntu1404_7.0-28_amd64.deb
$ sudo apt-get update
$ sudo apt-get install cuda
$ sudo apt-get install 

7.0でないと怒られた.というか今はcuda=7.0, cudnn=6.5 v2のみをサポートしているよう.

  • tensorflow 6.0
$ sudo pip install "six==1.9.0"
$ sudo pip install --upgrade https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.6.0-cp27-none-linux_x86_64.whl # versionは適宜変更
実際に使うまでの2 phases
  • construction phase
    • that assembles a graph
  • execution phase
    • uses a session to execute ops in the graph
Session
  • Computational graphが実行される場所のようなもの
  • graph上のオペレーション(演算)をデバイス(cpu, gpu)にマップする
Varialbe
  • Stateを持つように扱える
  • 詳細は,コード参照
  • 普通はこっち (chainer varialbe にみえる)
  • よく使うのは
    • variable.eval(): 評価
    • variable.value(): Tensor object
    • variable.op: Operation
Fetches
  • Fetchesはsess.run([fetche, ..])といれる.
  • input: list of varialbe, then output: list of nparray
  • input: variable, then output: np.type
Feeds
  • sessの中でデータを関数に食わせるという意味でfeedだとおもう.
  • tf.placeholder(...)を使う
  • こっちはtheano function like

サンプルコードはここ

Graphの作り方は,Theanoに似ているかな.

Interactive Usage

ipythonで使う場合

  • 1. interactive session
  • 2. variable作る
  • 3. variable.initializer.run()
  • 4. varialbe.eval()

こんな感じで評価する(結構めんどい)
こうすることで,sessionの中で保持するvarialbeを保持する必要がなくなる

sess = tf.InteractiveSession()
weights = tf.Variable(tf.random_normal([784, 200], stddev=0.35), name="weights")
weights.initializer.run()
weights.eval()

を使う,