You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2022/09/13 14:30:33 UTC

[GitHub] [beam] AnandInguva commented on a diff in pull request #23173: Add a tensorflow example to the run_inference_basic notebook

AnandInguva commented on code in PR #23173:
URL: https://github.com/apache/beam/pull/23173#discussion_r969706333


##########
examples/notebooks/beam-ml/run_inference_basic.ipynb:
##########
@@ -1362,6 +1308,408 @@
         "      | beam.Map(print)\n",
         "  )\n"
       ]
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "# TensorFlow - Examples\n",
+        "\n",
+        "[TFX-BSL](https://github.com/tensorflow/tfx-bsl) offers an API that returns a ModelHandler that integrates with beam and works with TensorFlow models.\n",
+        "\n",
+        "It also works with TensorFlow models hosted on VertexAI."
+      ],
+      "metadata": {
+        "id": "F_vhQJTgcc_y"
+      }
+    },
+    {
+      "cell_type": "code",
+      "source": [
+        "# The TF ModelHandler is impelemented in tfx_bsl 1.10 and later.\n",
+        "!pip install tfx_bsl==1.10.0 --quiet\n",
+        "#NOTE: You may need to restart your runtime."
+      ],
+      "metadata": {
+        "colab": {
+          "base_uri": "https://localhost:8080/"
+        },
+        "id": "a2FoAA-feV5L",
+        "outputId": "638e06bd-a057-40ec-d263-4fb87568ef4f"
+      },
+      "execution_count": 1,
+      "outputs": [
+        {
+          "output_type": "stream",
+          "name": "stdout",
+          "text": [
+            "\u001b[K     |████████████████████████████████| 21.6 MB 2.4 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 10.9 MB 29.1 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 578.0 MB 11 kB/s \n",
+            "\u001b[K     |████████████████████████████████| 2.4 MB 40.8 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 270 kB 60.2 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 508 kB 35.2 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 47 kB 3.7 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 151 kB 54.8 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 62 kB 1.4 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 124 kB 64.1 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 180 kB 38.9 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 83 kB 1.8 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 183 kB 52.2 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 255 kB 66.0 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 435 kB 52.7 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 173 kB 59.7 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 267 kB 55.2 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 267 kB 63.3 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 148 kB 57.6 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 235 kB 57.7 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 1.0 MB 51.5 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 119 kB 62.0 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 119 kB 53.5 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 118 kB 45.3 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 234 kB 62.3 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 234 kB 58.1 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 234 kB 56.7 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 234 kB 66.2 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 234 kB 36.8 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 265 kB 56.4 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 148 kB 55.4 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 147 kB 65.9 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 4.6 MB 35.9 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 5.9 MB 43.6 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 1.1 MB 50.5 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 438 kB 49.5 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 1.7 MB 48.0 MB/s \n",
+            "\u001b[?25h  Building wheel for dill (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
+            "  Building wheel for google-apitools (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
+            "  Building wheel for docopt (setup.py) ... \u001b[?25l\u001b[?25hdone\n"
+          ]
+        }
+      ]
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "## Authenticate\n",
+        "\n",
+        "Authorize yourself so that you can save and load models."
+      ],
+      "metadata": {
+        "id": "8RHZxqB1HLlr"
+      }
+    },
+    {
+      "cell_type": "code",
+      "source": [
+        "from google.colab import auth\n",
+        "auth.authenticate_user()"
+      ],
+      "metadata": {
+        "id": "qDdGKYOoevNb"
+      },
+      "execution_count": 2,
+      "outputs": []
+    },
+    {
+      "cell_type": "code",
+      "source": [
+        "import argparse\n",
+        "\n",
+        "import tensorflow as tf\n",
+        "from tensorflow import keras\n",
+        "from tensorflow_serving.apis import prediction_log_pb2\n",
+        "\n",
+        "import apache_beam as beam\n",
+        "from apache_beam.ml.inference.base import RunInference\n",
+        "import tfx_bsl\n",
+        "from tfx_bsl.public.beam.run_inference import CreateModelHandler\n",
+        "from tfx_bsl.public import tfxio\n",
+        "from tfx_bsl.public.proto import model_spec_pb2\n",
+        "from tensorflow_metadata.proto.v0 import schema_pb2\n",
+        "\n",
+        "import numpy\n",
+        "\n",
+        "from typing import Dict, Text, Any, Tuple, List\n",
+        "\n",
+        "from apache_beam.options.pipeline_options import PipelineOptions\n",
+        "\n",
+        "project = \"<Your Project>\"\n",

Review Comment:
   project and bucket are defined at the top as well



##########
examples/notebooks/beam-ml/run_inference_basic.ipynb:
##########
@@ -1362,6 +1308,408 @@
         "      | beam.Map(print)\n",
         "  )\n"
       ]
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "# TensorFlow - Examples\n",
+        "\n",
+        "[TFX-BSL](https://github.com/tensorflow/tfx-bsl) offers an API that returns a ModelHandler that integrates with beam and works with TensorFlow models.\n",
+        "\n",
+        "It also works with TensorFlow models hosted on VertexAI."
+      ],
+      "metadata": {
+        "id": "F_vhQJTgcc_y"
+      }
+    },
+    {
+      "cell_type": "code",
+      "source": [
+        "# The TF ModelHandler is impelemented in tfx_bsl 1.10 and later.\n",
+        "!pip install tfx_bsl==1.10.0 --quiet\n",
+        "#NOTE: You may need to restart your runtime."
+      ],
+      "metadata": {
+        "colab": {
+          "base_uri": "https://localhost:8080/"
+        },
+        "id": "a2FoAA-feV5L",
+        "outputId": "638e06bd-a057-40ec-d263-4fb87568ef4f"
+      },
+      "execution_count": 1,
+      "outputs": [
+        {
+          "output_type": "stream",
+          "name": "stdout",
+          "text": [
+            "\u001b[K     |████████████████████████████████| 21.6 MB 2.4 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 10.9 MB 29.1 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 578.0 MB 11 kB/s \n",
+            "\u001b[K     |████████████████████████████████| 2.4 MB 40.8 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 270 kB 60.2 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 508 kB 35.2 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 47 kB 3.7 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 151 kB 54.8 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 62 kB 1.4 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 124 kB 64.1 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 180 kB 38.9 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 83 kB 1.8 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 183 kB 52.2 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 255 kB 66.0 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 435 kB 52.7 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 173 kB 59.7 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 267 kB 55.2 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 267 kB 63.3 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 148 kB 57.6 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 235 kB 57.7 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 1.0 MB 51.5 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 119 kB 62.0 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 119 kB 53.5 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 118 kB 45.3 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 234 kB 62.3 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 234 kB 58.1 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 234 kB 56.7 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 234 kB 66.2 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 234 kB 36.8 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 265 kB 56.4 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 148 kB 55.4 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 147 kB 65.9 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 4.6 MB 35.9 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 5.9 MB 43.6 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 1.1 MB 50.5 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 438 kB 49.5 MB/s \n",
+            "\u001b[K     |████████████████████████████████| 1.7 MB 48.0 MB/s \n",
+            "\u001b[?25h  Building wheel for dill (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
+            "  Building wheel for google-apitools (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
+            "  Building wheel for docopt (setup.py) ... \u001b[?25l\u001b[?25hdone\n"
+          ]
+        }
+      ]
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "## Authenticate\n",

Review Comment:
   This cell is repeated



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org