TF 2.0 @ tf.functionの例

abcdaire

サインセクションのテンソルフロードキュメントには、次のコードスニペットがあります

@tf.function
def train(model, optimizer):
  train_ds = mnist_dataset()
  step = 0
  loss = 0.0
  accuracy = 0.0
  for x, y in train_ds:
    step += 1
    loss = train_one_step(model, optimizer, x, y)
    if tf.equal(step % 10, 0):
      tf.print('Step', step, ': loss', loss, '; accuracy', compute_accuracy.result())
  return step, loss, accuracy

step, loss, accuracy = train(model, optimizer)
print('Final step', step, ': loss', loss, '; accuracy', compute_accuracy.result())

step変数に関して小さな質問があります。これは整数であり、テンソルではありません。サインは整数などの組み込みのPython型をサポートしています。したがって、tf.equal(step%10,0)を単純にstep%10 == 0正しく変更できますか?

誰も

はい、あなたが正しい。整数変数ステップは、グラフ表現に変換された場合でもPython変数のままです。を呼び出すと、変換結果を確認できますtf.autograph.to_code(train.python_function)

すべてのコードを報告せずに、step変数関連部分のみを報告すると、次のことがわかります。

  def loop_body(loop_vars, loss_1, step_1):
    with ag__.function_scope('loop_body'):
      x, y = loop_vars
      step_1 += 1

まだPython操作です(そうでないstep_1.assign_add(1)場合は、手順1がであった場合になりますtf.Tensor)。

直筆とtf.functionの詳細については、私は記事読んで示唆https://pgaleone.eu/tensorflow/tf.function/2019/03/21/dissecting-tf-function-part-1/ときに何が起こるかを簡単に説明します関数が変換されます。

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

tf.layers.globalAveragePooling2d()のTFJSの例

分類Dev

tf.loadModel is not a function

分類Dev

2次元のtf.Variableでtf.scatter_updateを使用する

分類Dev

tf.layers.conv1dとtf.layers.conv2dの違い

分類Dev

C / C ++ TensorFlow hello_tf.c :(。text + 0xa): `TF_Version 'への未定義の参照

分類Dev

Tensorflow 2のtf.contrib.layers.fully_connected()?

分類Dev

tf.layers.conv2dとtf.contrib.slim.conv2dの違い

分類Dev

tf.nn_conv2dとtf.nn.depthwise_conv2dの違い

分類Dev

TF2-tf.functionとクラス変数が壊れています

分類Dev

'Tensor' object has no attribute 'numpy' in tf.function in TF 2.0

分類Dev

tf.data.Dataset.zip((images、labels))から2つのtf.datasetを取得する方法

分類Dev

@ tf.functionのif-else

分類Dev

TF 2.0のtf.GradientTapeはtf.gradientsと同等ですか?

分類Dev

tensorflowのtf.control_dependencies(tf.get_collection(tf.GraphKeys.UPDATE_OPS))

分類Dev

conditional assignment of tf.variable in Tensorflow 2

分類Dev

「tf.nn.relu(A)」と「tf.maximum(A、0)」は同じですか?

分類Dev

TF2 / [:、:、0]を使用したKerasスライステンソル

分類Dev

tf.contrib.layers.conv2dからtf.nn.conv2dへの切り替え

分類Dev

tf.constant([1,2,3])とtf.constant([[1,2,3]])の違いは何ですか

分類Dev

tf.nn.conv2dとtf.layers.conv2d

分類Dev

@ tf.functionデコレータでのTF2.0エラー?

分類Dev

Why tf manipulations are working only in the arbitrary function?

分類Dev

What is tracing with regard to tf.function

分類Dev

Tensorflow 2.0.0-alpha0:tf.logging.set_verbosity

分類Dev

トレーニング済みのTF1 protobufモデルをTF2にロードする方法は?

分類Dev

TF1からTF2で記述されたmatmulベースのnnを実装する方法

分類Dev

2つのコーパスのTf-Idf計算

分類Dev

tf.contrib.seq2seq.sequence_lossのパラメーター

分類Dev

tf.nn.softmax_cross_entropy_with_logits_v2MLPのゼロを返す

Related 関連記事

  1. 1

    tf.layers.globalAveragePooling2d()のTFJSの例

  2. 2

    tf.loadModel is not a function

  3. 3

    2次元のtf.Variableでtf.scatter_updateを使用する

  4. 4

    tf.layers.conv1dとtf.layers.conv2dの違い

  5. 5

    C / C ++ TensorFlow hello_tf.c :(。text + 0xa): `TF_Version 'への未定義の参照

  6. 6

    Tensorflow 2のtf.contrib.layers.fully_connected()?

  7. 7

    tf.layers.conv2dとtf.contrib.slim.conv2dの違い

  8. 8

    tf.nn_conv2dとtf.nn.depthwise_conv2dの違い

  9. 9

    TF2-tf.functionとクラス変数が壊れています

  10. 10

    'Tensor' object has no attribute 'numpy' in tf.function in TF 2.0

  11. 11

    tf.data.Dataset.zip((images、labels))から2つのtf.datasetを取得する方法

  12. 12

    @ tf.functionのif-else

  13. 13

    TF 2.0のtf.GradientTapeはtf.gradientsと同等ですか?

  14. 14

    tensorflowのtf.control_dependencies(tf.get_collection(tf.GraphKeys.UPDATE_OPS))

  15. 15

    conditional assignment of tf.variable in Tensorflow 2

  16. 16

    「tf.nn.relu(A)」と「tf.maximum(A、0)」は同じですか?

  17. 17

    TF2 / [:、:、0]を使用したKerasスライステンソル

  18. 18

    tf.contrib.layers.conv2dからtf.nn.conv2dへの切り替え

  19. 19

    tf.constant([1,2,3])とtf.constant([[1,2,3]])の違いは何ですか

  20. 20

    tf.nn.conv2dとtf.layers.conv2d

  21. 21

    @ tf.functionデコレータでのTF2.0エラー?

  22. 22

    Why tf manipulations are working only in the arbitrary function?

  23. 23

    What is tracing with regard to tf.function

  24. 24

    Tensorflow 2.0.0-alpha0:tf.logging.set_verbosity

  25. 25

    トレーニング済みのTF1 protobufモデルをTF2にロードする方法は?

  26. 26

    TF1からTF2で記述されたmatmulベースのnnを実装する方法

  27. 27

    2つのコーパスのTf-Idf計算

  28. 28

    tf.contrib.seq2seq.sequence_lossのパラメーター

  29. 29

    tf.nn.softmax_cross_entropy_with_logits_v2MLPのゼロを返す

ホットタグ

アーカイブ