KZKY memo

自分用メモ.

TensorFlow: Python API: Transformation

記事を書いている時点では,v6.0なので注意

Casting

  • tf.string_to_number
  • tf.to_double
  • tf.to_float
  • tf.to_bfloat16
  • tf.to_int32
  • tf.to_int64
  • tf.cast

特に言及なし.

sample codes

Shapes and Shaping

  • tf.shape
  • tf.size
  • tf.rank
  • tf.reshape
  • tf.squeeze
  • tf.expand_dims

rankはTensorの次元数を返す

squeezeは,dim=1のテンソルの次元を削除.

expand_dimsは,dim=1のテンソルの次元を追加. batchsize=1のサンプルを作るのによく使用される.

sample codes

Slicing and Joining

  • tf.slice
  • tf.split
  • tf.tile
  • tf.pad
  • tf.concat
  • tf.pack
  • tf.unpack
  • tf.reverse_sequence
  • tf.reverse
  • tf.transpose
  • tf.gather
  • tf.dynamic_partition
  • tf.dynamic_stitch

reverse_sequenceは,逆向きにデータを突っ込むorBiRNNのために用意されているような感じを受ける.サンプル(sequenceとなっている前提)毎に,sequcneを反転させる.

gatherは,もともとのtensorから必要なindeciesのみ集める.

dynamic_stitchは,n個のTensorを指定したindicesでつなぎ合わせる感じ.

indiciesが2d-tensorの場合は,

merged[indices[m][i], ...] = data[m][i, ...]

のようになるので,

  • len(data) = indices.shape[0]
  • data[j][0] = indices.shape[1] for any j
  • indicesのエレメントは,0: len(data) * len(data[j].shape[0])で, uniqueな値を取る

が条件のようではある.

sample codes