Created
October 22, 2019 07:00
-
-
Save analyticsindiamagazine/d937efaacbb54593ecd07be98b28f491 to your computer and use it in GitHub Desktop.
TensorFlow Eager Execution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "Eager_execution.ipynb", | |
"provenance": [] | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "8bzIFsLrNz3e", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"import tensorflow as tf\n", | |
"\n", | |
"tf.compat.v1.enable_eager_execution()\n" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "joWTC7PzPIW_", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 34 | |
}, | |
"outputId": "2fc5b6b5-b691-484c-aedd-f47f0140be4b" | |
}, | |
"source": [ | |
"tf.executing_eagerly()" | |
], | |
"execution_count": 2, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"True" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 2 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"attributes": { | |
"classes": [ | |
"py" | |
], | |
"id": "" | |
}, | |
"colab_type": "code", | |
"outputId": "ccfd13ce-8d79-4765-bafb-7a9e6bb4132f", | |
"id": "vSTmGyALNcUn", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 34 | |
} | |
}, | |
"source": [ | |
"x = [[2.]]\n", | |
"m = tf.matmul(x, x)\n", | |
"print(\"hello, {}\".format(m))" | |
], | |
"execution_count": 3, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"hello, [[4.]]\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab_type": "code", | |
"outputId": "d9f77cf9-e100-4492-eec3-85875ffb6fd7", | |
"id": "xk136sOrNcUq", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 68 | |
} | |
}, | |
"source": [ | |
"a = tf.constant([[1, 2],[3, 4]])\n", | |
"print(a)" | |
], | |
"execution_count": 4, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"tf.Tensor(\n", | |
"[[1 2]\n", | |
" [3 4]], shape=(2, 2), dtype=int32)\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"attributes": { | |
"classes": [ | |
"py" | |
], | |
"id": "" | |
}, | |
"colab_type": "code", | |
"id": "Ui025t1qqEfm", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 51 | |
}, | |
"outputId": "cda5a93b-432e-42e3-d5b7-ef1bdae58f1e" | |
}, | |
"source": [ | |
"# Use NumPy values\n", | |
"import numpy as np\n", | |
"\n", | |
"c = np.multiply(a, a)\n", | |
"print(c)" | |
], | |
"execution_count": 5, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"[[ 1 4]\n", | |
" [ 9 16]]\n" | |
], | |
"name": "stdout" | |
} | |
] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment