LoginSignup
2
4

More than 5 years have passed since last update.

TensorFlow に関する整理 by シニアエンジニア

Last updated at Posted at 2018-08-17

大手SIerで、AIエンジニアを目指すシニア・エンジニアによる”Tensorflow”に取り組んだ際の知識の備忘録。

1.様々な記述方法

TensorFlowは、非常に変化が激しいフレームワークであり、使いやすいもの・すぐれたものを随時吸収していく。その際、基本的な記述方法(生TensorFlow)ではない、記述方法によるコーディングが可能である為、その当たりを整理する。
https://qiita.com/rindai87/items/546991f5ecae0ef7cde3

記述中!
に加え、Eager execution も整理する。

オリジナル、ラッパー、define-by-run の違い

1.1. 基本的な記載方法

・セッション・オペレーションによる計算

 プログラム - 演算グラフ(Session) - 操作(オペレーション;コマンド)で処理が構成

・項目等

 項目としては、定数(constant)、変数(variables)、外部参照(placeholder)

・記述例

import tensorflow as tf

定義

inc = tf.constant(1, name="inc")                 # 定数
cnt = tf.Variable(0, name="cnt")                 # 変数
y = tf.placeholder(tf.int32, name="y")           # プレースホルダー(箱)

処理(オペレーション)の記述

add_opv = tf.add(cnt, inc)                        # 加算
up_op = tf.assign(cnt, add_opv)                   # 値の更新
add_opp = tf.add(cnt, y)                          # 値を代入して加算

実行環境(セッション)の記述(&実行)

with tf.Session() as sess:                        # セッション開始
    sess.run(tf.global_variables_initializer())   # 変数の初期化

    print(sess.run(up_op))                        # 値の更新を実行
    print(sess.run(up_op))                        #   〃
    print(sess.run(up_op))                        #   〃

    print(sess.run(add_opp, feed_dict={y:1}))     # 値を代入しての加算
    print(sess.run(add_opp, feed_dict={y:3}))     #  〃

処理結果

1
2
3
4
6

1.2. グラフ・レスな記載方法(contrib.learn)

 プログラム - 演算グラフ(Session) - 操作(オペレーション;コマンド)で処理が構成

2
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
4