Skip to content

Commit

Permalink
Merge pull request google-ai-edge#57 from googlesamples/py_version_9.1
Browse files Browse the repository at this point in the history
Updating pyMediaPipe versions for the Python API to 0.9.1
  • Loading branch information
PaulTR authored Feb 14, 2023
2 parents 5f983ed + a91213f commit 4871542
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 7 deletions.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/hand_landmarker/python/hand_landmarker.ipynb

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"outputs": [],
"source": [
"!pip install -q flatbuffers==2.0.0\n",
"!pip install -q mediapipe==0.9.0.1"
"!pip install -q mediapipe==0.9.1"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion examples/object_detection/python/object_detector.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/text_classification/python/text_classifier.ipynb
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","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}
{"cells":[{"cell_type":"markdown","metadata":{"id":"h2q27gKz1H20"},"source":["##### Copyright 2023 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.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}
2 changes: 1 addition & 1 deletion examples/text_embedder/python/text_embedder.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
],
"source": [
"!pip install -q flatbuffers==2.0.0\n",
"!pip install -q mediapipe==0.9.0.1"
"!pip install -q mediapipe==0.9.1"
]
},
{
Expand Down

0 comments on commit 4871542

Please sign in to comment.