forked from google-ai-edge/mediapipe
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request google-ai-edge#29 from tuan4192/feature/python-exa…
…mples-change-mediapipe-version-to-0.9.0.1 update version mediapipe to 0.9.0.1
- Loading branch information
Showing
5 changed files
with
5 additions
and
5 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"cells":[{"cell_type":"markdown","metadata":{"id":"h2q27gKz1H20"},"source":["##### Copyright 2022 The MediaPipe Authors. All Rights Reserved."]},{"cell_type":"code","execution_count":1,"metadata":{"cellView":"form","id":"TUfAcER1oUS6","executionInfo":{"status":"ok","timestamp":1670014043908,"user_tz":480,"elapsed":5,"user":{"displayName":"Khanh LeViet","userId":"02074344541050284452"}}},"outputs":[],"source":["#@title Licensed under the Apache License, Version 2.0 (the \"License\");\n","# you may not use this file except in compliance with the License.\n","# You may obtain a copy of the License at\n","#\n","# https://www.apache.org/licenses/LICENSE-2.0\n","#\n","# Unless required by applicable law or agreed to in writing, software\n","# distributed under the License is distributed on an \"AS IS\" BASIS,\n","# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n","# See the License for the specific language governing permissions and\n","# limitations under the License."]},{"cell_type":"markdown","metadata":{"id":"L_cQX8dWu4Dv"},"source":["# Text Classifier with MediaPipe Tasks\n","\n","This notebook shows you how to use MediaPipe Tasks Python API to classify text."]},{"cell_type":"markdown","metadata":{"id":"99IjoWCyDk7g"},"source":["## Preparation\n","\n","Let's start with installing MediaPipe.\n","\n","*Notes:*\n","* *If you see an error about `flatbuffers` incompatibility, it's fine to ignore it. MediaPipe requires a newer version of flatbuffers (v2), which is incompatible with the older version of Tensorflow (v2.9) currently preinstalled on Colab.*\n","* *If you install MediaPipe outside of Colab, you only need to run `pip install mediapipe`. It isn't necessary to explicitly install `flatbuffers`.*"]},{"cell_type":"code","execution_count":2,"metadata":{"id":"gxbHBsF-8Y_l","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1670014059359,"user_tz":480,"elapsed":15455,"user":{"displayName":"Khanh LeViet","userId":"02074344541050284452"}},"outputId":"f465eff2-324a-4183-c741-0cbeec839d10"},"outputs":[{"output_type":"stream","name":"stdout","text":["\u001b[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n","tensorflow 2.9.2 requires flatbuffers<2,>=1.12, but you have flatbuffers 2.0 which is incompatible.\u001b[0m\n","\u001b[K |████████████████████████████████| 33.0 MB 1.4 MB/s \n","\u001b[?25h"]}],"source":["!pip install -q flatbuffers==2.0.0\n","!pip install -q mediapipe==0.9.0"]},{"cell_type":"markdown","metadata":{"id":"QGNTJpASRDpI"},"source":["Then download an off-the-shelf model. Check out the [MediaPipe documentation](https://developers.google.com/mediapipe/solutions/text/text_classifier#models) for more text classification models that you can use."]},{"cell_type":"code","execution_count":3,"metadata":{"id":"OMjuVQiDYJKF","executionInfo":{"status":"ok","timestamp":1670014060065,"user_tz":480,"elapsed":710,"user":{"displayName":"Khanh LeViet","userId":"02074344541050284452"}}},"outputs":[],"source":["!wget -O classifier.tflite -q https://storage.googleapis.com/mediapipe-tasks/text_classifier/bert_text_classifier.tflite"]},{"cell_type":"markdown","metadata":{"id":"Iy4r2_ePylIa"},"source":["## Running inference\n","\n","Here are the steps to run text classification using MediaPipe.\n","\n","Check out the [MediaPipe documentation](https://developers.google.com/mediapipe/solutions/text/text_classifier/python) to learn more about configuration options that this solution supports."]},{"cell_type":"code","source":["# Define the input text that you wants the model to classify.\n","INPUT_TEXT = \"I'm looking forward to what will come next.\""],"metadata":{"id":"VwROOdg9l1KM","executionInfo":{"status":"ok","timestamp":1670014060066,"user_tz":480,"elapsed":4,"user":{"displayName":"Khanh LeViet","userId":"02074344541050284452"}}},"execution_count":4,"outputs":[]},{"cell_type":"code","execution_count":5,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"Yl_Oiye4mUuo","outputId":"27efcd55-7c17-493e-d591-2fe0c838e4df","executionInfo":{"status":"ok","timestamp":1670014061338,"user_tz":480,"elapsed":1275,"user":{"displayName":"Khanh LeViet","userId":"02074344541050284452"}}},"outputs":[{"output_type":"stream","name":"stdout","text":["positive (0.99)\n"]}],"source":["# STEP 1: Import the necessary modules.\n","from mediapipe.tasks import python\n","from mediapipe.tasks.python import text\n","\n","# STEP 2: Create an TextClassifier object.\n","base_options = python.BaseOptions(model_asset_path=\"classifier.tflite\")\n","options = text.TextClassifierOptions(base_options=base_options)\n","classifier = python.text.TextClassifier.create_from_options(options)\n","\n","# STEP 3: Classify the input text.\n","classification_result = classifier.classify(INPUT_TEXT)\n","\n","# STEP 4: Process the classification result. In this case, print out the most likely category.\n","top_category = classification_result.classifications[0].categories[0]\n","print(f'{top_category.category_name} ({top_category.score:.2f})')"]},{"cell_type":"code","execution_count":5,"metadata":{"id":"WPO6rvNJTkPd","executionInfo":{"status":"ok","timestamp":1670014061338,"user_tz":480,"elapsed":3,"user":{"displayName":"Khanh LeViet","userId":"02074344541050284452"}}},"outputs":[],"source":[]}],"metadata":{"colab":{"provenance":[]},"kernelspec":{"display_name":"Python 3 (ipykernel)","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.7.13"}},"nbformat":4,"nbformat_minor":0} | ||
{"cells":[{"cell_type":"markdown","metadata":{"id":"h2q27gKz1H20"},"source":["##### Copyright 2022 The MediaPipe Authors. All Rights Reserved."]},{"cell_type":"code","execution_count":1,"metadata":{"cellView":"form","executionInfo":{"elapsed":5,"status":"ok","timestamp":1670014043908,"user":{"displayName":"Khanh LeViet","userId":"02074344541050284452"},"user_tz":480},"id":"TUfAcER1oUS6"},"outputs":[],"source":["#@title Licensed under the Apache License, Version 2.0 (the \"License\");\n","# you may not use this file except in compliance with the License.\n","# You may obtain a copy of the License at\n","#\n","# https://www.apache.org/licenses/LICENSE-2.0\n","#\n","# Unless required by applicable law or agreed to in writing, software\n","# distributed under the License is distributed on an \"AS IS\" BASIS,\n","# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n","# See the License for the specific language governing permissions and\n","# limitations under the License."]},{"cell_type":"markdown","metadata":{"id":"L_cQX8dWu4Dv"},"source":["# Text Classifier with MediaPipe Tasks\n","\n","This notebook shows you how to use MediaPipe Tasks Python API to classify text."]},{"cell_type":"markdown","metadata":{"id":"99IjoWCyDk7g"},"source":["## Preparation\n","\n","Let's start with installing MediaPipe.\n","\n","*Notes:*\n","* *If you see an error about `flatbuffers` incompatibility, it's fine to ignore it. MediaPipe requires a newer version of flatbuffers (v2), which is incompatible with the older version of Tensorflow (v2.9) currently preinstalled on Colab.*\n","* *If you install MediaPipe outside of Colab, you only need to run `pip install mediapipe`. It isn't necessary to explicitly install `flatbuffers`.*"]},{"cell_type":"code","execution_count":2,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":15455,"status":"ok","timestamp":1670014059359,"user":{"displayName":"Khanh LeViet","userId":"02074344541050284452"},"user_tz":480},"id":"gxbHBsF-8Y_l","outputId":"f465eff2-324a-4183-c741-0cbeec839d10"},"outputs":[{"name":"stdout","output_type":"stream","text":["\u001b[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n","tensorflow 2.9.2 requires flatbuffers<2,>=1.12, but you have flatbuffers 2.0 which is incompatible.\u001b[0m\n","\u001b[K |████████████████████████████████| 33.0 MB 1.4 MB/s \n","\u001b[?25h"]}],"source":["!pip install -q flatbuffers==2.0.0\n","!pip install -q mediapipe==0.9.0.1"]},{"cell_type":"markdown","metadata":{"id":"QGNTJpASRDpI"},"source":["Then download an off-the-shelf model. Check out the [MediaPipe documentation](https://developers.google.com/mediapipe/solutions/text/text_classifier#models) for more text classification models that you can use."]},{"cell_type":"code","execution_count":3,"metadata":{"executionInfo":{"elapsed":710,"status":"ok","timestamp":1670014060065,"user":{"displayName":"Khanh LeViet","userId":"02074344541050284452"},"user_tz":480},"id":"OMjuVQiDYJKF"},"outputs":[],"source":["!wget -O classifier.tflite -q https://storage.googleapis.com/mediapipe-tasks/text_classifier/bert_text_classifier.tflite"]},{"cell_type":"markdown","metadata":{"id":"Iy4r2_ePylIa"},"source":["## Running inference\n","\n","Here are the steps to run text classification using MediaPipe.\n","\n","Check out the [MediaPipe documentation](https://developers.google.com/mediapipe/solutions/text/text_classifier/python) to learn more about configuration options that this solution supports."]},{"cell_type":"code","execution_count":4,"metadata":{"executionInfo":{"elapsed":4,"status":"ok","timestamp":1670014060066,"user":{"displayName":"Khanh LeViet","userId":"02074344541050284452"},"user_tz":480},"id":"VwROOdg9l1KM"},"outputs":[],"source":["# Define the input text that you wants the model to classify.\n","INPUT_TEXT = \"I'm looking forward to what will come next.\""]},{"cell_type":"code","execution_count":5,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":1275,"status":"ok","timestamp":1670014061338,"user":{"displayName":"Khanh LeViet","userId":"02074344541050284452"},"user_tz":480},"id":"Yl_Oiye4mUuo","outputId":"27efcd55-7c17-493e-d591-2fe0c838e4df"},"outputs":[{"name":"stdout","output_type":"stream","text":["positive (0.99)\n"]}],"source":["# STEP 1: Import the necessary modules.\n","from mediapipe.tasks import python\n","from mediapipe.tasks.python import text\n","\n","# STEP 2: Create an TextClassifier object.\n","base_options = python.BaseOptions(model_asset_path=\"classifier.tflite\")\n","options = text.TextClassifierOptions(base_options=base_options)\n","classifier = python.text.TextClassifier.create_from_options(options)\n","\n","# STEP 3: Classify the input text.\n","classification_result = classifier.classify(INPUT_TEXT)\n","\n","# STEP 4: Process the classification result. In this case, print out the most likely category.\n","top_category = classification_result.classifications[0].categories[0]\n","print(f'{top_category.category_name} ({top_category.score:.2f})')"]},{"cell_type":"code","execution_count":5,"metadata":{"executionInfo":{"elapsed":3,"status":"ok","timestamp":1670014061338,"user":{"displayName":"Khanh LeViet","userId":"02074344541050284452"},"user_tz":480},"id":"WPO6rvNJTkPd"},"outputs":[],"source":[]}],"metadata":{"colab":{"provenance":[]},"kernelspec":{"display_name":"Python 3 (ipykernel)","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.7.13"}},"nbformat":4,"nbformat_minor":0} |