"vscode:/vscode.git/clone" did not exist on "42411c1bc84e6f01c063a2380475f6a903afd28f"
Unverified Commit 8955b748 authored by Taylor's avatar Taylor Committed by GitHub
Browse files

Fixes Neutral Style Transfer example (#10779)

* Fixes Neutral Style Transfer example

Fixes tensorflow/models#9451 by creating image from example that can be downloaded.

* Fixes Neutral Style Transfer Adam reference

In TF2 this function moved from tf.optimizers.Adam(). Only TF2 is supported on Google colab

https://www.tensorflow.org/api_docs/python/tf/compat/v1/train/AdamOptimizer

* Update 4_Neural_Style_Transfer_with_Eager_Execution.ipynb

Updates tf.keras.preprocessing.image() function reference to TF2 equivalent to restore functionality on Google colab.

https://www.tensorflow.org/api_docs/python/tf/keras/preprocessing/image

* Fixes Neutral Style Transfer example

Eager Execution is now enabled by default in TF2

https://www.tensorflow.org/api_docs/python/tf/executing_eagerly
parent 19a47a9e
...@@ -171,7 +171,7 @@ ...@@ -171,7 +171,7 @@
"%tensorflow_version 1.x\n", "%tensorflow_version 1.x\n",
"import tensorflow as tf\n", "import tensorflow as tf\n",
"\n", "\n",
"from tensorflow.python.keras.preprocessing import image as kp_image\n", "from tensorflow.keras.utils import image_dataset_from_directory as kp_image\n",
"from tensorflow.python.keras import models \n", "from tensorflow.python.keras import models \n",
"from tensorflow.python.keras import losses\n", "from tensorflow.python.keras import losses\n",
"from tensorflow.python.keras import layers\n", "from tensorflow.python.keras import layers\n",
...@@ -180,30 +180,6 @@ ...@@ -180,30 +180,6 @@
"execution_count": 0, "execution_count": 0,
"outputs": [] "outputs": []
}, },
{
"metadata": {
"id": "L7sjDODq67HQ",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"We’ll begin by enabling [eager execution](https://www.tensorflow.org/guide/eager). Eager execution allows us to work through this technique in the clearest and most readable way. "
]
},
{
"metadata": {
"id": "sfjsSAtNrqQx",
"colab_type": "code",
"colab": {}
},
"cell_type": "code",
"source": [
"tf.enable_eager_execution()\n",
"print(\"Eager execution: {}\".format(tf.executing_eagerly()))"
],
"execution_count": 0,
"outputs": []
},
{ {
"metadata": { "metadata": {
"id": "IOiGrIV1iERH", "id": "IOiGrIV1iERH",
...@@ -828,7 +804,7 @@ ...@@ -828,7 +804,7 @@
" init_image = load_and_process_img(content_path)\n", " init_image = load_and_process_img(content_path)\n",
" init_image = tf.Variable(init_image, dtype=tf.float32)\n", " init_image = tf.Variable(init_image, dtype=tf.float32)\n",
" # Create our optimizer\n", " # Create our optimizer\n",
" opt = tf.train.AdamOptimizer(learning_rate=5, beta1=0.99, epsilon=1e-1)\n", " opt = tf.optimizers.Adam(learning_rate=5, epsilon=1e-1)\n",
"\n", "\n",
" # For displaying intermediate images \n", " # For displaying intermediate images \n",
" iter_count = 1\n", " iter_count = 1\n",
...@@ -945,6 +921,8 @@ ...@@ -945,6 +921,8 @@
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
"#from google.colab import files\n", "#from google.colab import files\n",
"#final_img = Image.fromarray(best)\n",
"#final_img.save('wave_turtle.png')\n",
"#files.download('wave_turtle.png')" "#files.download('wave_turtle.png')"
], ],
"execution_count": 0, "execution_count": 0,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment