Created
October 23, 2019 10:54
-
-
Save analyticsindiamagazine/462eed12ed69af03fdaf19c4d4895df9 to your computer and use it in GitHub Desktop.
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": "TF2.ipynb", | |
"provenance": [] | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "RG_ZLJEvLJrh", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 102 | |
}, | |
"outputId": "b3c60a06-8d92-4779-ad92-00b7e1c48f0d" | |
}, | |
"source": [ | |
"try:\n", | |
" %tensorflow_version 2.x #gpu\n", | |
"except Exception:\n", | |
" pass\n", | |
"\n", | |
"import tensorflow as tf" | |
], | |
"execution_count": 1, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"`%tensorflow_version` only switches the major version: `1.x` or `2.x`.\n", | |
"You set: `2.x #gpu`. This will be interpreted as: `2.x`.\n", | |
"\n", | |
"\n", | |
"TensorFlow 2.x selected.\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "IiTeSVImc4_9", | |
"colab_type": "code", | |
"outputId": "342fa7c3-ab12-4692-a205-6389606b01f0", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 34 | |
} | |
}, | |
"source": [ | |
"print(tf.__version__)" | |
], | |
"execution_count": 2, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"2.0.0\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "goV9-wq1c8Ig", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"x = tf.Variable(0.)\n", | |
"y = tf.Variable(1.)" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "DxgLYyAOiCZG", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"for i in range(50):\n", | |
" x.assign(x+y)\n", | |
" y.assign(y/2)" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "Ra2SBRsTKH4S", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 34 | |
}, | |
"outputId": "6729116f-1577-4787-839c-c8eca2c1ede9" | |
}, | |
"source": [ | |
"print(x.numpy())" | |
], | |
"execution_count": 5, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"2.0\n" | |
], | |
"name": "stdout" | |
} | |
] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment