{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "name": "tensorflow-2.0.ipynb", "version": "0.3.2", "provenance": [], "collapsed_sections": [], "include_colab_link": true }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "accelerator": "GPU" }, "cells": [ { "cell_type": "markdown", "metadata": { "id": "view-in-github", "colab_type": "text" }, "source": [ "\"Open" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "2QQJJyDzqGRb" }, "source": [ "# টেন্সর-ফ্লো ২.০ ইনস্টলেশন \n", "\n", "কিছু জিনিস ঠিকমতো কাজ না করতে পারে, টেস্ট করতে থাকুন \n" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "RBAeIwOMrYk8" }, "source": [ "## এনভায়রনমেন্ট ঠিক করে নেই " ] }, { "cell_type": "code", "metadata": { "attributes": { "classes": [ "py" ], "id": "" }, "colab_type": "code", "id": "7aFsD8csqEff", "colab": {} }, "source": [ "from __future__ import absolute_import, division, print_function, unicode_literals\n", "\n", "import tensorflow as tf\n", "\n", "import numpy as np\n", "\n", "# tf.enable_eager_execution()" ], "execution_count": 0, "outputs": [] }, { "cell_type": "markdown", "metadata": { "id": "KIAL4s0UT0_4", "colab_type": "text" }, "source": [ "এখন কি আছে?" ] }, { "cell_type": "code", "metadata": { "id": "Q2A2OwZUT4Ub", "colab_type": "code", "outputId": "8c17c232-2a6e-436a-aad2-882e3477a009", "colab": { "base_uri": "https://localhost:8080/", "height": 34 } }, "source": [ "tf.__version__" ], "execution_count": 0, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "'2.0.0-alpha0'" ] }, "metadata": { "tags": [] }, "execution_count": 3 } ] }, { "cell_type": "markdown", "metadata": { "id": "zrGTAgw3UIDx", "colab_type": "text" }, "source": [ "টেন্সর-ফ্লো ২.০ ইনস্টল করে নেই, জিপিইউ ভার্সন " ] }, { "cell_type": "code", "metadata": { "id": "Hd9aatIiTvK2", "colab_type": "code", "outputId": "ad5ad8df-2dbe-49a0-fb64-71a423917c19", "colab": { "base_uri": "https://localhost:8080/", "height": 530 } }, "source": [ "#!pip install tensorflow==2.0.0-alpha0\n", "!pip install --upgrade tensorflow-gpu==2.0.0-alpha0" ], "execution_count": 0, "outputs": [ { "output_type": "stream", "text": [ "Collecting tensorflow-gpu==2.0.0-alpha0\n", "\u001b[?25l Downloading https://files.pythonhosted.org/packages/1a/66/32cffad095253219d53f6b6c2a436637bbe45ac4e7be0244557210dc3918/tensorflow_gpu-2.0.0a0-cp36-cp36m-manylinux1_x86_64.whl (332.1MB)\n", "\u001b[K |████████████████████████████████| 332.1MB 73kB/s \n", "\u001b[?25hRequirement already satisfied, skipping upgrade: numpy<2.0,>=1.14.5 in /usr/local/lib/python3.6/dist-packages (from tensorflow-gpu==2.0.0-alpha0) (1.16.3)\n", "Requirement already satisfied, skipping upgrade: wheel>=0.26 in /usr/local/lib/python3.6/dist-packages (from tensorflow-gpu==2.0.0-alpha0) (0.33.1)\n", "Requirement already satisfied, skipping upgrade: absl-py>=0.7.0 in /usr/local/lib/python3.6/dist-packages (from tensorflow-gpu==2.0.0-alpha0) (0.7.1)\n", "Requirement already satisfied, skipping upgrade: astor>=0.6.0 in /usr/local/lib/python3.6/dist-packages (from tensorflow-gpu==2.0.0-alpha0) (0.7.1)\n", "Collecting tb-nightly<1.14.0a20190302,>=1.14.0a20190301 (from tensorflow-gpu==2.0.0-alpha0)\n", "\u001b[?25l Downloading https://files.pythonhosted.org/packages/a9/51/aa1d756644bf4624c03844115e4ac4058eff77acd786b26315f051a4b195/tb_nightly-1.14.0a20190301-py3-none-any.whl (3.0MB)\n", "\u001b[K |████████████████████████████████| 3.0MB 44.4MB/s \n", "\u001b[?25hRequirement already satisfied, skipping upgrade: termcolor>=1.1.0 in /usr/local/lib/python3.6/dist-packages (from tensorflow-gpu==2.0.0-alpha0) (1.1.0)\n", "Requirement already satisfied, skipping upgrade: protobuf>=3.6.1 in /usr/local/lib/python3.6/dist-packages (from tensorflow-gpu==2.0.0-alpha0) (3.7.1)\n", "Requirement already satisfied, skipping upgrade: grpcio>=1.8.6 in /usr/local/lib/python3.6/dist-packages (from tensorflow-gpu==2.0.0-alpha0) (1.15.0)\n", "Requirement already satisfied, skipping upgrade: six>=1.10.0 in /usr/local/lib/python3.6/dist-packages (from tensorflow-gpu==2.0.0-alpha0) (1.12.0)\n", "Requirement already satisfied, skipping upgrade: gast>=0.2.0 in /usr/local/lib/python3.6/dist-packages (from tensorflow-gpu==2.0.0-alpha0) (0.2.2)\n", "Collecting google-pasta>=0.1.2 (from tensorflow-gpu==2.0.0-alpha0)\n", "\u001b[?25l Downloading https://files.pythonhosted.org/packages/64/bb/f1bbc131d6294baa6085a222d29abadd012696b73dcbf8cf1bf56b9f082a/google_pasta-0.1.5-py3-none-any.whl (51kB)\n", "\u001b[K |████████████████████████████████| 61kB 30.9MB/s \n", "\u001b[?25hRequirement already satisfied, skipping upgrade: keras-applications>=1.0.6 in /usr/local/lib/python3.6/dist-packages (from tensorflow-gpu==2.0.0-alpha0) (1.0.7)\n", "Requirement already satisfied, skipping upgrade: keras-preprocessing>=1.0.5 in /usr/local/lib/python3.6/dist-packages (from tensorflow-gpu==2.0.0-alpha0) (1.0.9)\n", "Collecting tf-estimator-nightly<1.14.0.dev2019030116,>=1.14.0.dev2019030115 (from tensorflow-gpu==2.0.0-alpha0)\n", "\u001b[?25l Downloading https://files.pythonhosted.org/packages/13/82/f16063b4eed210dc2ab057930ac1da4fbe1e91b7b051a6c8370b401e6ae7/tf_estimator_nightly-1.14.0.dev2019030115-py2.py3-none-any.whl (411kB)\n", "\u001b[K |████████████████████████████████| 419kB 55.4MB/s \n", "\u001b[?25hRequirement already satisfied, skipping upgrade: werkzeug>=0.11.15 in /usr/local/lib/python3.6/dist-packages (from tb-nightly<1.14.0a20190302,>=1.14.0a20190301->tensorflow-gpu==2.0.0-alpha0) (0.15.2)\n", "Requirement already satisfied, skipping upgrade: markdown>=2.6.8 in /usr/local/lib/python3.6/dist-packages (from tb-nightly<1.14.0a20190302,>=1.14.0a20190301->tensorflow-gpu==2.0.0-alpha0) (3.1)\n", "Requirement already satisfied, skipping upgrade: setuptools in /usr/local/lib/python3.6/dist-packages (from protobuf>=3.6.1->tensorflow-gpu==2.0.0-alpha0) (41.0.1)\n", "Requirement already satisfied, skipping upgrade: h5py in /usr/local/lib/python3.6/dist-packages (from keras-applications>=1.0.6->tensorflow-gpu==2.0.0-alpha0) (2.8.0)\n", "Installing collected packages: tb-nightly, google-pasta, tf-estimator-nightly, tensorflow-gpu\n", "Successfully installed google-pasta-0.1.5 tb-nightly-1.14.0a20190301 tensorflow-gpu-2.0.0a0 tf-estimator-nightly-1.14.0.dev2019030115\n" ], "name": "stdout" } ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "x_G1zZT5qEfh" }, "source": [ "# tf.Session() কোথায় গেল?" ] }, { "cell_type": "code", "metadata": { "id": "1WsmrcZZUdJw", "colab_type": "code", "outputId": "61b9e106-d8df-4b58-a6e9-0e908ac256eb", "colab": { "base_uri": "https://localhost:8080/", "height": 51 } }, "source": [ "hello = tf.constant(\"Hello World from Bangladesh\")\n", "print(\"Tensor:\", hello)\n", "print(\"Value :\", hello.numpy())" ], "execution_count": 0, "outputs": [ { "output_type": "stream", "text": [ "Tensor: tf.Tensor(b'Hello World from Bangladesh', shape=(), dtype=string)\n", "Value : b'Hello World from Bangladesh'\n" ], "name": "stdout" } ] }, { "cell_type": "code", "metadata": { "colab_type": "code", "id": "5hien2IEqwLQ", "outputId": "2af79bbf-1021-4a4d-8d40-1819b702f785", "colab": { "base_uri": "https://localhost:8080/", "height": 34 } }, "source": [ "tf.executing_eagerly()" ], "execution_count": 0, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "True" ] }, "metadata": { "tags": [] }, "execution_count": 5 } ] }, { "cell_type": "markdown", "metadata": { "id": "DzclV2ebaJMT", "colab_type": "text" }, "source": [ "## ইগার এক্সিকিউশন দিয়ে " ] }, { "cell_type": "code", "metadata": { "id": "TuVTcnr3YJTN", "colab_type": "code", "outputId": "2be2dad7-f5ea-4765-a656-5932c589d37c", "colab": { "base_uri": "https://localhost:8080/", "height": 34 } }, "source": [ "import tensorflow as tf\n", "\n", "x = [[2.]]\n", "y = [[1.]]\n", "k = tf.add(x, y)\n", "print(k) # k is the Tensor [[3.]]" ], "execution_count": 0, "outputs": [ { "output_type": "stream", "text": [ "tf.Tensor([[3.]], shape=(1, 1), dtype=float32)\n" ], "name": "stdout" } ] }, { "cell_type": "markdown", "metadata": { "id": "L3tROI00X5su", "colab_type": "text" }, "source": [ "## আগে টেন্সর-ফ্লো কোর দিয়ে যদি করতাম " ] }, { "cell_type": "code", "metadata": { "id": "TrlHs93pX_lX", "colab_type": "code", "outputId": "a692c7df-ccb7-4038-e4e2-74fcf5f4dbf2", "colab": { "base_uri": "https://localhost:8080/", "height": 34 } }, "source": [ "# এটা করা ঠিক না \n", "import tensorflow.compat.v1 as tf\n", "tf.disable_v2_behavior()\n", "\n", "x = tf.placeholder(tf.float32, shape=[1, 1])\n", "y = tf.placeholder(tf.float32, shape=[1, 1])\n", "k = tf.add(x, y) # k is a Tensor, but has no value assigned yet\n", "with tf.Session() as sess:\n", " k = sess.run(k, feed_dict={x: [[2.]], y: [[1.]]})\n", "print(k) # k is 3." ], "execution_count": 0, "outputs": [ { "output_type": "stream", "text": [ "[[3.]]\n" ], "name": "stdout" } ] } ] }