Skip to content

Commit a03c1ac

Browse files
committed
Fix review comments.
Add note about keras layers and models.
1 parent e1be4e9 commit a03c1ac

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

samples/core/guide/autograph_control_flow.ipynb

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@
385385
"with tf.Graph().as_default(): \n",
386386
" with tf.Session():\n",
387387
" try:\n",
388-
" print(tf_f(tf.constant(0)).eval())\n",
388+
" print(f(tf.constant(0)).eval())\n",
389389
" except tf.errors.InvalidArgumentError as e:\n",
390390
" print('Got error message:\\n %s' % e.message)"
391391
],
@@ -451,7 +451,8 @@
451451
"def f(n):\n",
452452
" z = []\n",
453453
" # We ask you to tell us the element dtype of the list\n",
454-
" z = autograph.utils.set_element_type(z, tf.int32)\n",
454+
" autograph.utils.set_element_type(z, tf.int32)\n",
455+
" \n",
455456
" for i in range(n):\n",
456457
" z.append(i)\n",
457458
" # when you're done with the list, stack it\n",
@@ -474,7 +475,7 @@
474475
},
475476
"cell_type": "markdown",
476477
"source": [
477-
"### Nested If statement"
478+
"### Nested if statements"
478479
]
479480
},
480481
{
@@ -571,17 +572,31 @@
571572
"execution_count": 0,
572573
"outputs": []
573574
},
575+
{
576+
"metadata": {
577+
"id": "hy99pRWpMcuN",
578+
"colab_type": "text"
579+
},
580+
"cell_type": "markdown",
581+
"source": [
582+
""
583+
]
584+
},
574585
{
575586
"metadata": {
576587
"id": "4LfnJjm0Bm0B",
577588
"colab_type": "text"
578589
},
579590
"cell_type": "markdown",
580591
"source": [
581-
"## Advanced example: A training, loop in-graph\n",
592+
"## Advanced example: A training loop in-graph\n",
582593
"\n",
583594
"Writing control flow in AutoGraph is easy, so running a training loop in a TensorFlow graph should be easy as well! \n",
584595
"\n",
596+
"<!--TODO(markdaoust) link to examples showing autograph **in** keras models when ready-->\n",
597+
"\n",
598+
"Important: While this example wraps up a `tf.keras.Model` using autograph, `tf.contrib.autograph` is fully compatible with `tf.keras` and can be used in the definitions [custom of keras layers and models](http://tensorflow.org/guide/keras#build_advanced_models). The easiest way is to `@autograph.convert()` the `call` method.\n",
599+
"\n",
585600
"Here, we show an example of training a simple Keras model on MNIST, where the entire training process -- loading batches, calculating gradients, updating parameters, calculating validation accuracy, and repeating until convergence -- is done in-graph."
586601
]
587602
},
@@ -700,20 +715,20 @@
700715
" # to convert these lists into their graph equivalent,\n",
701716
" # we need to specify the element type of the lists.\n",
702717
" train_losses = []\n",
703-
" train_losses = autograph.utils.set_element_type(train_losses, tf.float32)\n",
718+
" autograph.utils.set_element_type(train_losses, tf.float32)\n",
704719
" test_losses = []\n",
705-
" test_losses = autograph.utils.set_element_type(test_losses, tf.float32)\n",
720+
" autograph.utils.set_element_type(test_losses, tf.float32)\n",
706721
" train_accuracies = []\n",
707-
" train_accuracies = autograph.utils.set_element_type(train_accuracies, tf.float32)\n",
722+
" autograph.utils.set_element_type(train_accuracies, tf.float32)\n",
708723
" test_accuracies = []\n",
709-
" test_accuracies = autograph.utils.set_element_type(test_accuracies, tf.float32)\n",
724+
" autograph.utils.set_element_type(test_accuracies, tf.float32)\n",
710725
" \n",
711726
" # This entire training loop will be run in-graph.\n",
712727
" i = tf.constant(0)\n",
713728
" while i < hp.max_steps:\n",
714729
" train_x, train_y = get_next_batch(train_ds)\n",
715730
" test_x, test_y = get_next_batch(test_ds)\n",
716-
" # add get next\n",
731+
"\n",
717732
" step_train_loss, step_train_accuracy = fit(m, train_x, train_y, opt)\n",
718733
" step_test_loss, step_test_accuracy = predict(m, test_x, test_y)\n",
719734
" if i % (hp.max_steps // 10) == 0:\n",
@@ -790,19 +805,6 @@
790805
],
791806
"execution_count": 0,
792807
"outputs": []
793-
},
794-
{
795-
"metadata": {
796-
"id": "ZpEIfs5jn6jw",
797-
"colab_type": "code",
798-
"colab": {}
799-
},
800-
"cell_type": "code",
801-
"source": [
802-
""
803-
],
804-
"execution_count": 0,
805-
"outputs": []
806808
}
807809
]
808810
}

0 commit comments

Comments
 (0)