From af1216e371e1f05c2ae5ce84edec65ce641cb878 Mon Sep 17 00:00:00 2001 From: Helena Kloosterman Date: Tue, 6 Jul 2021 19:07:42 +0200 Subject: [PATCH 01/21] Markdown and HTML conversion in CI (#148) * Add Notebook->Markdown and HTML script for CI * Convert notebooks to Markdown/HTML on push to main --- .ci/convert_notebooks.sh | 14 ++++++++ .github/workflows/convert_notebooks.yml | 48 +++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 .ci/convert_notebooks.sh create mode 100644 .github/workflows/convert_notebooks.yml diff --git a/.ci/convert_notebooks.sh b/.ci/convert_notebooks.sh new file mode 100644 index 00000000000..2b773353cb5 --- /dev/null +++ b/.ci/convert_notebooks.sh @@ -0,0 +1,14 @@ +# Execute notebooks and convert them to Markdown and HTML + +htmldir=$PWD"/html_files" +markdowndir=$PWD"/markdown_files" +mkdir -p $htmldir +mkdir -p $markdowndir + +git ls-files "*.ipynb" | while read notebook; do + executed_notebook=${notebook/.ipynb/-with-output.ipynb} + echo $executed_notebook + jupyter nbconvert --execute --to notebook --output $executed_notebook --output-dir . --ExecutePreprocessor.kernel_name="python3" $notebook + jupyter nbconvert --to markdown $executed_notebook --output-dir $markdowndir + jupyter nbconvert --to html $executed_notebook --output-dir $htmldir +done diff --git a/.github/workflows/convert_notebooks.yml b/.github/workflows/convert_notebooks.yml new file mode 100644 index 00000000000..e7068b50939 --- /dev/null +++ b/.github/workflows/convert_notebooks.yml @@ -0,0 +1,48 @@ +# Execute notebooks and convert them to Markdown and HTML + +name: Convert Notebooks +on: + workflow_dispatch: + push: + branches: + - 'main' + paths: + - "**.ipynb" +jobs: + build: + strategy: + fail-fast: false + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v1 + with: + python-version: 3.7 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install -r .ci/ci-requirements.txt + python -m pip freeze > pip-freeze.txt + - name: Archive pip freeze + uses: actions/upload-artifact@v2 + with: + name: pip-freeze + path: pip-freeze.txt + - name: Modify Notebooks + # Change settings in slower notebooks to speed up notebook execution + run: | + sed -i 's/NUM_FRAMES = 100/NUM_FRAMES = 5/g' notebooks/202-vision-superresolution/202-vision-superresolution-video.ipynb + sed -i 's/epochs = 15/epochs = 2/g' notebooks/301-tensorflow-training-openvino/301-tensorflow-training-openvino.ipynb + - name: convert_notebooks + run: bash .ci/convert_notebooks.sh + - name: Save HTML files + uses: actions/upload-artifact@v2 + with: + name: html_files + path: html_files + - name: Save Markdown files + uses: actions/upload-artifact@v2 + with: + name: markdown_files + path: markdown_files From c827be97412b60775ac8daffa6371ba8830de1f3 Mon Sep 17 00:00:00 2001 From: Helena Kloosterman Date: Tue, 6 Jul 2021 19:09:04 +0200 Subject: [PATCH 02/21] Change VP09 to vp09 (#149) Official name is vp09, VP09 shows an FFMPEG warning about falling back to vp09 --- notebooks/201-vision-monodepth/201-vision-monodepth.ipynb | 4 ++-- .../202-vision-superresolution-video.ipynb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/notebooks/201-vision-monodepth/201-vision-monodepth.ipynb b/notebooks/201-vision-monodepth/201-vision-monodepth.ipynb index 13bf407580a..960b68fcd33 100644 --- a/notebooks/201-vision-monodepth/201-vision-monodepth.ipynb +++ b/notebooks/201-vision-monodepth/201-vision-monodepth.ipynb @@ -343,11 +343,11 @@ "# If SCALE_OUTPUT is 0.5, the width and height of the result video\n", "# will be half the width and height of the input video\n", "SCALE_OUTPUT = 0.5\n", - "# The format to use for video encoding. VP09 is slow,\n", + "# The format to use for video encoding. vp09 is slow,\n", "# but it works on most systems.\n", "# Try the THEO encoding if you have FFMPEG installed.\n", "# FOURCC = cv2.VideoWriter_fourcc(*\"THEO\")\n", - "FOURCC = cv2.VideoWriter_fourcc(*\"VP09\")\n", + "FOURCC = cv2.VideoWriter_fourcc(*\"vp09\")\n", "\n", "# Create Path objects for the input video and the resulting video\n", "video_path = Path(VIDEO_FILE)\n", diff --git a/notebooks/202-vision-superresolution/202-vision-superresolution-video.ipynb b/notebooks/202-vision-superresolution/202-vision-superresolution-video.ipynb index 26c03924490..df9861914aa 100644 --- a/notebooks/202-vision-superresolution/202-vision-superresolution-video.ipynb +++ b/notebooks/202-vision-superresolution/202-vision-superresolution-video.ipynb @@ -281,9 +281,9 @@ "# Number of frames to read from the input video. Set to 0 to read all frames.\n", "NUM_FRAMES = 100\n", "# The format for saving the result video's\n", - "# VP09 is slow, but widely available. If you have FFMPEG installed, you can\n", + "# vp09 is slow, but widely available. If you have FFMPEG installed, you can\n", "# change the FOURCC to `*\"THEO\"` to improve video writing speed\n", - "FOURCC = cv2.VideoWriter_fourcc(*\"VP09\")" + "FOURCC = cv2.VideoWriter_fourcc(*\"vp09\")" ] }, { From 7db8f3a5e51b0246e5c9ca28306590ef73072f0b Mon Sep 17 00:00:00 2001 From: Helena Kloosterman Date: Tue, 6 Jul 2021 19:09:40 +0200 Subject: [PATCH 03/21] Only run nbval tests if notebook or python files changed (#150) * Only run nbval tests if notebook or python files changed --- .github/workflows/nbval.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/nbval.yml b/.github/workflows/nbval.yml index 0a4b9baedf7..8be3152d192 100644 --- a/.github/workflows/nbval.yml +++ b/.github/workflows/nbval.yml @@ -5,8 +5,11 @@ on: pull_request: branches: - 'main' - paths-ignore: - - '**.md' + paths: + - 'notebooks/**.ipynb' + - 'notebooks/**.py' + - 'requirements.txt' + - '.ci/*requirements.txt' schedule: - cron: '30 8 * * *' From ed1b032d9de9d1f965e1ab26bb0f1c50db84d7da Mon Sep 17 00:00:00 2001 From: Helena Kloosterman Date: Tue, 6 Jul 2021 19:11:22 +0200 Subject: [PATCH 04/21] Pin openvino-dev to 2021.4.* (#146) Also fix merge conflicts --- .../301-tensorflow-training-openvino.ipynb | 3 --- requirements.txt | 8 +------- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/notebooks/301-tensorflow-training-openvino/301-tensorflow-training-openvino.ipynb b/notebooks/301-tensorflow-training-openvino/301-tensorflow-training-openvino.ipynb index 4ba3562e1cb..4b8ce32188b 100644 --- a/notebooks/301-tensorflow-training-openvino/301-tensorflow-training-openvino.ipynb +++ b/notebooks/301-tensorflow-training-openvino/301-tensorflow-training-openvino.ipynb @@ -93,9 +93,6 @@ "import mo_tf\n", "from openvino.inference_engine import IECore\n", "\n", - "# Enable oneDNN CPU performance optimizations in TensorFlow for faster training on Intel CPUs\n", - "os.environ['TF_ENABLE_ONEDNN_OPTS'] = '1'\n", - "\n", "import tensorflow as tf\n", "from tensorflow import keras\n", "from tensorflow.keras import layers\n", diff --git a/requirements.txt b/requirements.txt index 0ff7f02656f..b6d6b9bb981 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -openvino-dev==2021.4 +openvino-dev[onnx,tensorflow2]==2021.4.* matplotlib<3.4 gdown pytube @@ -6,7 +6,6 @@ pytube # ONNX notebook requirements geffnet==0.9.8 fastseg -onnx ipywidgets torch>=1.5.1,<=1.7.1; sys_platform == 'darwin' @@ -15,11 +14,6 @@ torchvision>=0.6.1,<=0.8.2; sys_platform == 'darwin' torch>=1.5.1+cpu,<=1.7.1+cpu; sys_platform =='linux' or platform_system == 'Windows' torchvision>=0.6.1+cpu,<=0.8.2+cpu; sys_platform =='linux' or platform_system == 'Windows' -# Tensorflow notebook requirements -tensorflow==2.5.* -networkx>=1.11 -defusedxml>=0.5.0 - # Jupyter requirements jupyterlab From 9acfa0c415d5af58b2a53d6140fcc75149af9bda Mon Sep 17 00:00:00 2001 From: Helena Kloosterman Date: Thu, 8 Jul 2021 22:25:30 +0200 Subject: [PATCH 05/21] Add Model Tools notebook (#140) * Show info-alert if GPU not available for GPU benchmark * Add NotebookAlert and GPUNotFoundAlert class to notebook_utils --- .../104-model-tools/104-model-tools.ipynb | 415 ++++++++++++++++++ notebooks/utils/notebook_utils.py | 40 +- 2 files changed, 454 insertions(+), 1 deletion(-) create mode 100644 notebooks/104-model-tools/104-model-tools.ipynb diff --git a/notebooks/104-model-tools/104-model-tools.ipynb b/notebooks/104-model-tools/104-model-tools.ipynb new file mode 100644 index 00000000000..1890cba4bf8 --- /dev/null +++ b/notebooks/104-model-tools/104-model-tools.ipynb @@ -0,0 +1,415 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "artificial-discretion", + "metadata": {}, + "source": [ + "# Working with Open Model Zoo Models\n", + "\n", + "## Model Downloader, Model Converter, Info Dumper and Benchmark Tool" + ] + }, + { + "cell_type": "markdown", + "id": "usual-karen", + "metadata": { + "tags": [ + "hide" + ] + }, + "source": [ + "This demo shows how to download a model from Open Model Zoo, convert it to OpenVINO's IR format, show information about the model, and benchmark the model.\n", + "\n", + "| Tool | Command | Description |\n", + "|------------------|-------------------|-----------------------------------------------------------------------------------|\n", + "| Model Downloader | `omz_downloader` | Download models from Open Model Zoo |\n", + "| Model Converter | `omz_converter` | Convert Open Model Zoo models that are not in OpenVINO's IR format to that format |\n", + "| Info Dumper | `omz_info_dumper` | Print information about Open Model Zoo models |\n", + "| Benchmark Tool | `benchmark_app` | Benchmark model performance by computing inference time |" + ] + }, + { + "cell_type": "markdown", + "id": "fec90f61-08f3-4417-8a6f-ec61c9e5955b", + "metadata": { + "tags": [ + "hide" + ] + }, + "source": [ + "## Preparation\n", + "\n", + "### Model Name\n", + "\n", + "Set `model_name` to the name of the Open Model Zoo model to use in this notebook. Refer to the list of [public](https://github.com/openvinotoolkit/open_model_zoo/blob/master/models/public/index.md) and [Intel](https://github.com/openvinotoolkit/open_model_zoo/blob/master/models/intel/index.md) models for names of models that can be used." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "21d6d2be-05a8-4c52-9ad9-af892a76db1f", + "metadata": {}, + "outputs": [], + "source": [ + "# model_name = \"resnet-50-pytorch\"\n", + "model_name = \"mobilenet-v2-pytorch\"" + ] + }, + { + "cell_type": "markdown", + "id": "f0206a22-dc33-4666-ab2b-86386b97caca", + "metadata": { + "tags": [ + "hide" + ] + }, + "source": [ + "### Imports" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "impressed-uncertainty", + "metadata": {}, + "outputs": [], + "source": [ + "import os.path\n", + "import subprocess\n", + "import sys\n", + "from pathlib import Path\n", + "from openvino.inference_engine import IECore\n", + "from IPython.display import Markdown\n", + "import json\n", + "\n", + "# Import an error checking function and define a backup class if notebook_utils is not available\n", + "sys.path.append(\"../utils\")\n", + "class SimpleGPUNotFoundAlert(object):\n", + " def __init__(self):\n", + " print(\"Running this cell requires an integrated GPU, which is not available on this system.\")\n", + " \n", + "try:\n", + " from notebook_utils import GPUNotFoundAlert\n", + "except:\n", + " GPUNotFoundAlert = SimpleGPUNotFoundAlert" + ] + }, + { + "cell_type": "markdown", + "id": "parental-assets", + "metadata": { + "tags": [ + "hide" + ] + }, + "source": [ + "### Settings and Configuration\n", + "\n", + "Set the file and directory paths. By default, this demo notebook downloads models from Open Model Zoo to a directory `open_model_zoo_models` in your `$HOME` directory. On Windows, the $HOME directory is usually `c:\\users\\username`, on Linux `/home/username`. If you want to change the folder, change `base_model_dir` in the cell below. \n", + "\n", + "You can change the following settings:\n", + "\n", + "* `base_model_dir`: Models will be downloaded into the `intel` and `public` folders in this directory.\n", + "* `omz_cache_dir`: Cache folder for Open Model Zoo. Specifying a cache directory is not required for Model Downloader and Model Converter, but it speeds up subsequent downloads.\n", + "* `precision`: If specified, download only models with this precision. " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "korean-agency", + "metadata": {}, + "outputs": [], + "source": [ + "base_model_dir = Path(\"~/open_model_zoo_models\").expanduser()\n", + "omz_cache_dir = Path(\"~/open_model_zoo_cache\").expanduser()\n", + "precision = \"FP16\"\n", + "\n", + "# Check if an iGPU is available on this system to use with Benchmark App\n", + "ie = IECore()\n", + "gpu_available = \"GPU\" in ie.available_devices\n", + "\n", + "print(f\"base_model_dir: {base_model_dir}, omz_cache_dir: {omz_cache_dir}, gpu_availble: {gpu_available}\")" + ] + }, + { + "cell_type": "markdown", + "id": "judicial-preview", + "metadata": {}, + "source": [ + "## Download Model from Open Model Zoo\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "id": "rising-interval", + "metadata": {}, + "source": [ + "Specify, display and run the Model Downloader command to download the model" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "df2b0446-0c49-41cf-9f3f-dec1232249f7", + "metadata": {}, + "outputs": [], + "source": [ + "## Uncomment the next line to show omz_downloader's help which explains the command line options\n", + "\n", + "# !omz_downloader --help" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "556d0c12-15cf-492d-a1ed-41dff5090eff", + "metadata": {}, + "outputs": [], + "source": [ + "download_command = f\"omz_downloader --name {model_name} --output_dir {base_model_dir} --cache_dir {omz_cache_dir}\"\n", + "display(Markdown(f\"Download command: `{download_command}`\"))\n", + "display(Markdown(f\"Downloading {model_name}...\"))\n", + "! $download_command" + ] + }, + { + "cell_type": "markdown", + "id": "proprietary-checklist", + "metadata": {}, + "source": [ + "## Convert Model to OpenVINO IR format\n", + "\n", + "Specify, display and run the Model Converter command to convert the model to IR format. Model Conversion may take a while. The output of the Model Converter command will be displayed. Conversion succeeded if the last lines of the output include `[ SUCCESS ] Generated IR version 10 model.` For downloaded models that are already in IR format, conversion will be skipped." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "11fe7461-90db-4585-b55f-b3df42b01274", + "metadata": {}, + "outputs": [], + "source": [ + "## Uncomment the next line to show omz_converter's help which explains the command line options\n", + "\n", + "# !omz_converter --help" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "engaged-academy", + "metadata": {}, + "outputs": [], + "source": [ + "convert_command = f\"omz_converter --name {model_name} --precisions {precision} --download_dir {base_model_dir} --output_dir {base_model_dir}\"\n", + "display(Markdown(f\"Convert command: `{convert_command}`\"))\n", + "display(Markdown(f\"Converting {model_name}...\"))\n", + "\n", + "! $convert_command" + ] + }, + { + "cell_type": "markdown", + "id": "aa8d655f-215d-4e3c-adcb-e8fd4a2e8ab4", + "metadata": {}, + "source": [ + "## Get Model Information\n", + "\n", + "The Info Dumper prints the following information for Open Model Zoo models:\n", + "\n", + "* Model name\n", + "* Description\n", + "* Framework that was used to train the model\n", + "* License url\n", + "* Precisions supported by the model\n", + "* Subdirectory: the location of the downloaded model\n", + "* Task type\n", + "\n", + "This information can be shown, by running `omz_info_dumper --name model_name` in a terminal. The information can also be parsed and used in scripts. \n", + "\n", + "In the next cell, we run Info Dumper, and use json to load the information in a dictionary. " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b8247daf-d3c5-4420-b4c8-d305ac4ace5b", + "metadata": {}, + "outputs": [], + "source": [ + "model_info_output = %sx omz_info_dumper --name $model_name\n", + "model_info = json.loads(model_info_output.get_nlstr())[0]\n", + "model_info" + ] + }, + { + "cell_type": "markdown", + "id": "7ea7e868-fd2d-4d11-9c87-7aa1f1301083", + "metadata": {}, + "source": [ + "Having the model information in a JSON file allows us to extract the path to the model directory, and build the path to the IR file." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "de1a319e-bbef-414c-921d-60938b4a01a8", + "metadata": {}, + "outputs": [], + "source": [ + "model_path = base_model_dir / Path(model_info[\"subdirectory\"]) / Path(f\"{precision}/{model_name}.xml\")\n", + "print(model_path, \"exists:\", model_path.exists())" + ] + }, + { + "cell_type": "markdown", + "id": "54e01154-f700-479f-9111-147c95595d46", + "metadata": {}, + "source": [ + "## Run Benchmark Tool\n", + "\n", + "By default, Benchmark Tool runs inference for 60 seconds in asynchronous mode on CPU. It returns inference speed as latency (milliseconds per image) and throughput (frames per second) values. " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "282452e8-24c7-49c0-bdb2-10677971c30f", + "metadata": {}, + "outputs": [], + "source": [ + "## Uncomment the next line to show benchmark_app's help which explains the command line options\n", + "\n", + "# !benchmark_app --help" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9812b0c8-8cd0-4840-bca3-a28171d055b7", + "metadata": {}, + "outputs": [], + "source": [ + "benchmark_command = f\"benchmark_app -m {model_path} -t 15\"\n", + "display(Markdown(f\"Benchmark command: `{benchmark_command}`\"))\n", + "display(Markdown(f\"Benchmarking {model_name} on CPU with async inference for 15 seconds...\"))\n", + "\n", + "! $benchmark_command" + ] + }, + { + "cell_type": "markdown", + "id": "75891996-cf53-4c76-ad3c-5fb468ccd7bb", + "metadata": {}, + "source": [ + "### Benchmark with Different Settings" + ] + }, + { + "cell_type": "markdown", + "id": "88d64dd7-789d-4536-ab8f-84999c73afaf", + "metadata": {}, + "source": [ + "`benchmark_app` displays logging information that is not always necessary. We parse the output with json and show a more compact result\n", + "\n", + "The following cells show some examples of `benchmark_app` with different parameters. Some useful parameters are:\n", + "\n", + "- `-d` Device to use for inference. For example: CPU, GPU, MULTI\n", + "- `-t` Time in number of seconds to run inference\n", + "- `-api` Use asynchronous (async) or synchronous (sync) inference\n", + "- `-b` Batch size\n", + "\n", + "\n", + "Run `! benchmark_app --help` to get an overview of all possible command line parameters.\n", + "\n", + "In the next cell, we define a `benchmark_model()` function that calls `benchmark_app`. This makes it easy to try different combinations." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7742390e-df71-45e1-9572-f3cbaa576ec3", + "metadata": {}, + "outputs": [], + "source": [ + "def benchmark_model(model, device=\"CPU\", seconds=60, api=\"async\", batch=1):\n", + " ie = IECore()\n", + " \n", + " if (\"GPU\" in device) and (\"GPU\" not in ie.available_devices):\n", + " GPUNotFoundAlert()\n", + " else:\n", + " benchmark_command = f\"benchmark_app -m {model_path} -d {device} -t {seconds} -api {api} -b {batch}\"\n", + " display(Markdown(f\"**Benchmark {model_name} with {device} for {seconds} seconds with {api} inference**\"))\n", + " display(Markdown(f\"Benchmark command: `{benchmark_command}`\"))\n", + "\n", + " benchmark_output = %sx $benchmark_command\n", + " benchmark_result = [line for line in benchmark_output if not (line.startswith(r\"[\") or line.startswith(\" \") or line==\"\")]\n", + " print(\"\\n\".join(benchmark_result))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e10480c6-ac6e-4852-a813-ece1dfcf016c", + "metadata": {}, + "outputs": [], + "source": [ + "benchmark_model(model_path, device=\"CPU\", seconds=15, api=\"async\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b1d4c745-a4c2-4242-a2e7-fff1eb098b98", + "metadata": {}, + "outputs": [], + "source": [ + "benchmark_model(model_path, device=\"AUTO\", seconds=15, api=\"async\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5d47e1cf-cb2f-4138-928c-b56891d5c318", + "metadata": {}, + "outputs": [], + "source": [ + "benchmark_model(model_path, device=\"GPU\", seconds=15, api=\"async\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4a1b0bb2-87c7-44c9-92bf-1d95aa1500a1", + "metadata": {}, + "outputs": [], + "source": [ + "benchmark_model(model_path, device=\"MULTI:CPU,GPU\", seconds=15, api=\"async\")" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "openvino_env", + "language": "python", + "name": "openvino_env" + }, + "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.9" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/notebooks/utils/notebook_utils.py b/notebooks/utils/notebook_utils.py index ef3ef3c49f0..2d4c3f4012b 100644 --- a/notebooks/utils/notebook_utils.py +++ b/notebooks/utils/notebook_utils.py @@ -12,7 +12,9 @@ import cv2 import matplotlib.pyplot as plt import numpy as np +from IPython.display import HTML, display from matplotlib.lines import Line2D +from openvino.inference_engine import IECore class Label(NamedTuple): @@ -85,7 +87,9 @@ def to_bgr(image_data) -> np.ndarray: return cv2.cvtColor(image_data, cv2.COLOR_RGB2BGR) -def segmentation_map_to_image(result: np.ndarray, colormap: np.ndarray, remove_holes=False): +def segmentation_map_to_image( + result: np.ndarray, colormap: np.ndarray, remove_holes=False +): """ Convert network result of floating point numbers to an RGB image with integer values from 0-255 by applying a colormap. @@ -179,3 +183,37 @@ def get_cpu_info(): cpu = platform.processor() return cpu + + +class NotebookAlert(Exception): + def __init__(self, message, alert_class): + self.message = message + self.alert_class = alert_class + self.show_message() + + def show_message(self): + display(HTML(f"""
{self.message}""")) + + +class GPUNotFoundAlert(NotebookAlert): + def __init__(self): + ie = IECore() + supported_devices = ie.available_devices + self.message = ( + "Running this cell requires an integrated GPU, " + "which is not available on this system. " + ) + self.alert_class = "warning" + if len(supported_devices) == 1: + self.message += ( + f"The following device is available: {ie.available_devices[0]}" + ) + else: + self.message += ( + "The following devices are available: " + f"{', '.join(ie.available_devices)}" + ) + self.show_message() + + def show_message(self): + display(HTML(f"""
{self.message}""")) From 47af6579c02f5af747a7491471f01db0c431fdf4 Mon Sep 17 00:00:00 2001 From: Ryan Loney Date: Thu, 8 Jul 2021 23:21:33 -0700 Subject: [PATCH 06/21] Add Chinese language README (#159) * Create README_ch.md README in Chinese with local mirror in installation section * Update README_ch.md Changed English URL * Update README.md Added simplified Chinese instructions link * Rename README_ch.md to README_cn.md * Update README.md Co-authored-by: Helena Kloosterman --- README.md | 2 + README_cn.md | 133 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 135 insertions(+) create mode 100644 README_cn.md diff --git a/README.md b/README.md index 5d68c6b18f3..0535d14efde 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +English | [简体中文](README_cn.md) + # 📚 OpenVINO Notebooks A collection of ready-to-run Jupyter\* notebooks for learning and experimenting with the OpenVINO™ Toolkit. The notebooks provide an introduction to OpenVINO basics and teach developers how to leverage our API for optimized deep learning inference. diff --git a/README_cn.md b/README_cn.md new file mode 100644 index 00000000000..339abd37338 --- /dev/null +++ b/README_cn.md @@ -0,0 +1,133 @@ +[English](README.md) | 简体中文 + +# 📚 OpenVINO Notebooks + +一些可以运行的Jupyter\* notebooks,用于学习和试验OpenVINO™开发套件。这些notebooks旨在提供OpenVINO基础知识的介绍,并教开发人员如何利用我们的API在应用程序中优化深度学习推理。 + +## ⚙️ 系统需求 + +这些notebooks几乎可以在任何地方运行—你的笔记本电脑,一个云虚拟机,甚至一个Docker容器。下表是目前支持的操作系统及Python版本。**注**:Python3.9目前还不支持,不过即将支持。 + +| Supported Operating System | [Python Version (64-bit)](https://www.python.org/) | +| :--------------------------------------------------------- | :------------------------------------------------- | +| Ubuntu\* 18.04 LTS, 64-bit | 3.6, 3.7, 3.8 | +| Ubuntu\* 20.04 LTS, 64-bit | 3.6, 3.7, 3.8 | +| Red Hat* Enterprise Linux* 8, 64-bit | 3.6, 3.8 | +| CentOS\* 7, 64-bit | 3.6, 3.7, 3.8 | +| macOS\* 10.15.x versions | 3.6, 3.7, 3.8 | +| Windows 10\*, 64-bit Pro, Enterprise or Education editions | 3.6, 3.7, 3.8 | +| Windows Server\* 2016 or higher | 3.6, 3.7, 3.8 | + +## 📝 安装指南 + +运行OpenVINO Notebooks需要预装Python和Git, 针对不同操作系统的安装参考以下指南: + +| [Windows 10](https://github.com/openvinotoolkit/openvino_notebooks/wiki/Windows) | [Ubuntu](https://github.com/openvinotoolkit/openvino_notebooks/wiki/Ubuntu) | [macOS](https://github.com/openvinotoolkit/openvino_notebooks/wiki/macOS) | [Red Hat](https://github.com/openvinotoolkit/openvino_notebooks/wiki/Red-Hat-and-CentOS) | [CentOS](https://github.com/openvinotoolkit/openvino_notebooks/wiki/Red-Hat-and-CentOS) | [Azure ML](https://github.com/openvinotoolkit/openvino_notebooks/wiki/AzureML) | +| -------------------------------------------------------------------------------- | --------------------------------------------------------------------------- | ------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------ | + +Python和Git安装完成后,参考以下步骤: + +### Step 1: 创建并激活 `openvino_env` 虚拟环境 + +#### Linux 和 macOS 命令: + +```bash +python3 -m venv openvino_env +source openvino_env/bin/activate +``` + +#### Windows 命令: + +```bash +python -m venv openvino_env +openvino_env\Scripts\activate +``` + +### Step 2: 获取源码 + +```bash +git clone https://github.com/openvinotoolkit/openvino_notebooks.git +cd openvino_notebooks +``` + +### Step 3: 安装并启动 Notebooks + +将pip升级到最新版本。 + +```bash +python -m pip install --upgrade pip +pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple +python -m ipykernel install --user --name openvino_env +``` + +## 💻 运行 Notebooks + +### 启动单个 Notebook + +如果你希望启动单个的notebook(如:Monodepth notebook),运行以下命令: + +```bash +jupyter notebook notebooks/201-vision-monodepth/201-vision-monodepth.ipynb +``` + +### 启动所有 Notebooks + +```bash +jupyter lab notebooks +``` + +在浏览器中,从Jupyter Lab侧边栏的文件浏览器中选择一个notebook文件,每个notebook文件都位于`notebooks`目录中的子目录中。 + + + +## 🧹 清理 + +### 停止 Jupyter Kernel + +按 `Ctrl-c` 结束 Jupyter session,会弹出一个提示框 `Shutdown this Jupyter server (y/[n])?` 输入 `y` 并按 `回车`。 + +### 注销虚拟环境 + +注销该虚拟环境:只需在激活了 `openvino_env` 的终端窗口中运行 `deactivate` 即可。 + +重新激活环境:在Linux上运行 `source openvino_env/bin/activate` 或者在Windows上运行 `openvino_env\Scripts\activate` 即可,然后输入 `jupyter lab` 或 `jupyter notebook` 即可重新运行notebooks。 + +### 删除虚拟环境_(可选)_ + +直接删除 `openvino_env` 目录即可删除虚拟环境: + +#### Linux 和 macOS: + +```bash +rm -rf openvino_env +``` + +#### Windows: + +```bash +rmdir /s openvino_env +``` + +### 从Jupyter中移除openvino_env Kernel + +```bash +jupyter kernelspec remove openvino_env +``` + +## ⚠️ 故障排除 + +如果以下方法无法解决您的问题,欢迎创建一个 [讨论话题](https://github.com/openvinotoolkit/openvino_notebooks/discussions) 或 [issue](https://github.com/openvinotoolkit/openvino_notebooks/issues) ! + +- 运行 `python check_install.py` 可以帮助检查一些常见的安装问题,该脚本位于openvino_notebooks 目录中。 + + 记得运行该脚本之前先激活 `openvino_env` 虚拟环境。 + +- 如果出现 `ImportError` ,请检查是否安装了 Jupyter Kernel。如需手动设置kernel,从 Jupyter Lab 或 Jupyter Notebook 的_Kernel->Change Kernel_菜单中选择openvino_env内核。 + +- 如果OpenVINO是全局安装的,不要在执行了setupvars.bat或setupvars.sh的终端中运行安装命令。 + +- 对于Windows系统,我们建议使用_Command Prompt (cmd.exe)_,而不是_PowerShell_。 + +--- + +\* Other names and brands may be claimed as the property of others. From 122566b7a25fb44ef26a31f9126a754c70a8b9c1 Mon Sep 17 00:00:00 2001 From: Ryan Loney Date: Sat, 10 Jul 2021 01:58:29 -0700 Subject: [PATCH 07/21] updated pip upgrade in README_cn.md (#161) --- README_cn.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README_cn.md b/README_cn.md index 339abd37338..98e3eebcc63 100644 --- a/README_cn.md +++ b/README_cn.md @@ -55,7 +55,7 @@ cd openvino_notebooks 将pip升级到最新版本。 ```bash -python -m pip install --upgrade pip +python -m pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple python -m ipykernel install --user --name openvino_env ``` From 261c7addf5f0a6a2120c003ab02333140ec46c4d Mon Sep 17 00:00:00 2001 From: Helena Kloosterman Date: Sat, 10 Jul 2021 14:27:20 +0200 Subject: [PATCH 08/21] pin ipykernel (#151) --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index b6d6b9bb981..041b721dceb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -22,3 +22,4 @@ ipython==7.10.* jedi==0.17.2 setuptools>=56.0.0 Pillow==8.2.* +ipykernel==5.* From a9e845a24797c8441927b1089d05253b8de6e54f Mon Sep 17 00:00:00 2001 From: Snyk bot Date: Sun, 11 Jul 2021 21:17:42 +0300 Subject: [PATCH 09/21] fix: requirements.txt to reduce vulnerabilities (#165) The following vulnerabilities are fixed by pinning transitive dependencies: - https://snyk.io/vuln/SNYK-PYTHON-PYGMENTS-1086606 - https://snyk.io/vuln/SNYK-PYTHON-PYGMENTS-1088505 --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 041b721dceb..ffc966c9668 100644 --- a/requirements.txt +++ b/requirements.txt @@ -23,3 +23,4 @@ jedi==0.17.2 setuptools>=56.0.0 Pillow==8.2.* ipykernel==5.* +pygments>=2.7.4 # not directly required, pinned by Snyk to avoid a vulnerability From a3a385ceb492aa0fedbef1f55778740da10887bf Mon Sep 17 00:00:00 2001 From: Raymond Lo Date: Sun, 11 Jul 2021 11:19:09 -0700 Subject: [PATCH 10/21] Update README_cn.md (#166) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added the word "English" (英语) Guide to ensure developer knows the other wikis are in English. @helena-intel --- README_cn.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README_cn.md b/README_cn.md index 98e3eebcc63..90a63ba0c94 100644 --- a/README_cn.md +++ b/README_cn.md @@ -20,7 +20,7 @@ ## 📝 安装指南 -运行OpenVINO Notebooks需要预装Python和Git, 针对不同操作系统的安装参考以下指南: +运行OpenVINO Notebooks需要预装Python和Git, 针对不同操作系统的安装参考以下英语指南: | [Windows 10](https://github.com/openvinotoolkit/openvino_notebooks/wiki/Windows) | [Ubuntu](https://github.com/openvinotoolkit/openvino_notebooks/wiki/Ubuntu) | [macOS](https://github.com/openvinotoolkit/openvino_notebooks/wiki/macOS) | [Red Hat](https://github.com/openvinotoolkit/openvino_notebooks/wiki/Red-Hat-and-CentOS) | [CentOS](https://github.com/openvinotoolkit/openvino_notebooks/wiki/Red-Hat-and-CentOS) | [Azure ML](https://github.com/openvinotoolkit/openvino_notebooks/wiki/AzureML) | | -------------------------------------------------------------------------------- | --------------------------------------------------------------------------- | ------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------ | From 56b5b85e9fb4e18dac2cb156e5a58d48b43b6b32 Mon Sep 17 00:00:00 2001 From: Helena Kloosterman Date: Sun, 11 Jul 2021 20:20:33 +0200 Subject: [PATCH 11/21] Minor CI test updates (#164) * Minor CI test updates - remove deprecated legacy installer from pip install in tests - add mirror to upgrade pip in install_requirements_china * Run nb validation CI tests on CI configuration change --- .github/workflows/codeql.yml | 2 +- .github/workflows/docker.yml | 3 ++- .github/workflows/install_requirements.yml | 2 +- .github/workflows/install_requirements_china.yml | 4 ++-- .github/workflows/nbval.yml | 1 + 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index f51f16006cb..433748a4771 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -34,7 +34,7 @@ jobs: run: | python -m pip install --upgrade pip if [ -f requirements.txt ]; - then pip install -r requirements.txt --use-deprecated=legacy-resolver; + then pip install -r requirements.txt; fi # Set the `CODEQL-PYTHON` environment variable to the Python executable # that includes the dependencies diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 0cfe3199b27..3087083d5cf 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -5,7 +5,8 @@ on: pull_request: paths: - "Dockerfile" - - ".openshift/**" + - ".docker/**" + - ".github/workflows/docker.yml" jobs: build: diff --git a/.github/workflows/install_requirements.yml b/.github/workflows/install_requirements.yml index bdf07be82b6..844692f4578 100644 --- a/.github/workflows/install_requirements.yml +++ b/.github/workflows/install_requirements.yml @@ -22,7 +22,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - python -m pip install -r .ci/dev-requirements.txt --use-deprecated=legacy-resolver + python -m pip install -r .ci/dev-requirements.txt python -m ipykernel install --user --name openvino_env python -m pip freeze > pip-freeze-${{ github.sha }}-${{matrix.os}}-${{ matrix.python }}.txt - name: Archive pip freeze diff --git a/.github/workflows/install_requirements_china.yml b/.github/workflows/install_requirements_china.yml index 053216b6ffe..71a52e32dd5 100644 --- a/.github/workflows/install_requirements_china.yml +++ b/.github/workflows/install_requirements_china.yml @@ -23,8 +23,8 @@ jobs: python-version: ${{ matrix.python }} - name: Install dependencies run: | - python -m pip install --upgrade pip - python -m pip install -r requirements.txt --use-deprecated=legacy-resolver -i https://pypi.tuna.tsinghua.edu.cn/simple + python -m pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple + python -m pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple python -m ipykernel install --user --name openvino_env python -m pip freeze > pip-freeze-${{ github.sha }}-${{matrix.os}}-${{ matrix.python }}.txt diff --git a/.github/workflows/nbval.yml b/.github/workflows/nbval.yml index 8be3152d192..7eb3c919439 100644 --- a/.github/workflows/nbval.yml +++ b/.github/workflows/nbval.yml @@ -10,6 +10,7 @@ on: - 'notebooks/**.py' - 'requirements.txt' - '.ci/*requirements.txt' + - '.github/workflows/nbval.yml' schedule: - cron: '30 8 * * *' From a16261c83f0079b66c5d16ee467094756bc1e762 Mon Sep 17 00:00:00 2001 From: Helena Kloosterman Date: Mon, 12 Jul 2021 12:17:45 +0200 Subject: [PATCH 12/21] Add Binder option (#160) * Create apt.txt * Create requirements.txt * Update apt.txt * Add MyBinder files * Delete notebooks that need >2GB memory from Binder image in postBuild --- .binder/apt.txt | 4 ++++ .binder/postBuild | 3 +++ .binder/requirements.txt | 21 +++++++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 .binder/apt.txt create mode 100644 .binder/postBuild create mode 100644 .binder/requirements.txt diff --git a/.binder/apt.txt b/.binder/apt.txt new file mode 100644 index 00000000000..da68a563f3c --- /dev/null +++ b/.binder/apt.txt @@ -0,0 +1,4 @@ +libpython3.7-dev +ffmpeg +libsm6 +libxext6 diff --git a/.binder/postBuild b/.binder/postBuild new file mode 100644 index 00000000000..c35a7ef9574 --- /dev/null +++ b/.binder/postBuild @@ -0,0 +1,3 @@ +rm -rf notebooks/102-pytorch-onnx-to-openvino +rm -rf notebooks/206-vision-paddlegan-anime +rm -rf notebooks/301-tensorflow-training-openvino diff --git a/.binder/requirements.txt b/.binder/requirements.txt new file mode 100644 index 00000000000..297c07ad49e --- /dev/null +++ b/.binder/requirements.txt @@ -0,0 +1,21 @@ +openvino-dev[onnx,tensorflow2]==2021.4.* +matplotlib<3.4 +gdown +pytube + +# ONNX notebook requirements +geffnet==0.9.8 +fastseg +ipywidgets + +torch>=1.5.1,<=1.7.1; sys_platform == 'darwin' +torchvision>=0.6.1,<=0.8.2; sys_platform == 'darwin' +--find-links https://download.pytorch.org/whl/torch_stable.html +torch>=1.5.1+cpu,<=1.7.1+cpu; sys_platform =='linux' or platform_system == 'Windows' +torchvision>=0.6.1+cpu,<=0.8.2+cpu; sys_platform =='linux' or platform_system == 'Windows' + +# Pin versions to prevent known dependency issues +ipython==7.10.* +jedi==0.17.2 +setuptools>=56.0.0 +Pillow==8.2.* From 49d51d7436ce6d13e0d8e797d567bec70feac5f6 Mon Sep 17 00:00:00 2001 From: Ryan Loney Date: Mon, 12 Jul 2021 12:51:45 -0700 Subject: [PATCH 13/21] Add table to notebooks readme (#168) * 001 and 002 added to notebooks/readme.md * Added remaining notebooks Still need to add remaining descriptions and preview images * Added monodepth and paddlegan previews * Update README.md Added more descriptions * Update README.md Added remaining descriptions, ready to merge first version * Update README.md Added link to full list of notebooks * Update README.md Removed 103 which has not been published yet --- README.md | 4 ++-- notebooks/README.md | 31 ++++++++++++++----------------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 0535d14efde..5d322e8ff84 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ English | [简体中文](README_cn.md) -# 📚 OpenVINO Notebooks +# 📚 OpenVINO™ Notebooks -A collection of ready-to-run Jupyter\* notebooks for learning and experimenting with the OpenVINO™ Toolkit. The notebooks provide an introduction to OpenVINO basics and teach developers how to leverage our API for optimized deep learning inference. +A collection of ready-to-run Jupyter\* notebooks for learning and experimenting with the OpenVINO™ Toolkit. The notebooks provide an introduction to OpenVINO basics and teach developers how to leverage our API for optimized deep learning inference. Currently we have an API reference, guides for converting/optimizing PyTorch/TensorFlow/PaddlePaddle models, and model demos. [Click here](notebooks/README.md) to see the list of included notebooks. ## ⚙️ System Requirements diff --git a/notebooks/README.md b/notebooks/README.md index d774c0c9a50..ca4a7c200c5 100644 --- a/notebooks/README.md +++ b/notebooks/README.md @@ -2,21 +2,18 @@ Each notebook is located in a directory. Please follow the instructions in the [README](https://github.com/openvinotoolkit/openvino_notebooks/) before launching Jupyter Lab or Jupyter Notebook. -### hello-world: -- `001-hello-world` - -### tool-usage: - -- `101-tensorflow-to-openvino` -- `102-pytorch-onnx-to-openvino` - -### demos: - -- `201-vision-monodepth` -- `202-vision-superresolution` -- `205-vision-background-removal` - -### training-tutorials: - -- `301-tensorflow-training-openvino` +| Notebook | Description | Preview | +| :---: | :--- | :----: | +| [001-hello-world](001-hello-world/001-hello-world.ipynb) |
  • A very basic introduction to OpenVINO's [Python API](https://docs.openvinotoolkit.org/latest/ie_python_api/annotated.html)
  • Shows how to do inference on a [mobilenetv3](https://docs.openvinotoolkit.org/latest/omz_models_model_mobilenet_v3_small_1_0_224_tf.html) image classification model
|
`['n02099267', 'flat-coated_retriever']` | +| [002-openvino-api](002-openvino-api/002-openvino-api.ipynb) | OpenVINO API tutorial that covers the following:
  • Load Inference Engine and Show Info
  • Loading a Model
    • IR Model
    • ONNX Model
  • Getting Information about a Model
    • Model Inputs
    • Model Outputs
  • Doing Inference on a Model
  • Reshaping and Resizing
    • Change Image Size
    • Change Batch Size
| | +| [101-tensorflow-to-openvino](101-tensorflow-to-openvino/101-tensorflow-to-openvino.ipynb) |
  • Demonstrates how to convert [TensorFlow](https://www.tensorflow.org/) models to OpenVINO IR
  • Uses Model Optimizer to convert the same [mobilenetv3](https://docs.openvinotoolkit.org/latest/omz_models_model_mobilenet_v3_small_1_0_224_tf.html) image classification model from `001-hello-world` notebook
|
`['n02099267', 'flat-coated_retriever']` | +| [102-pytorch-onnx-to-openvino](102-pytorch-onnx-to-openvino/102-pytorch-onnx-to-openvino.ipynb) |
  • Demonstrates how to convert [PyTorch](https://pytorch.org/) models to OpenVINO IR
  • Uses Model Optimizer to convert the open source [fastseg](https://docs.openvinotoolkit.org/latest/omz_models_model_mobilenet_v3_small_1_0_224_tf.html) semantic segmentation model
| | +| [104-model-tools](104-model-tools/104-model-tools.ipynb) |
  • Demonstrates how to download a model from Open Model Zoo, convert it to OpenVINO's IR format, show information about the model, and asynchronously benchmark the model on CPU, iGPU and both devices combined. | | +| [201-vision-monodepth](201-vision-monodepth/201-vision-monodepth.ipynb) |
    • Demonstrates Monocular Depth Estimation with MidasNet model in OpenVINO
    • Uses [OpenCV](https://opencv.org/) to load and process frames from an image and a video
    • Generates output video showing input and output side by side
    • Users can upload their own videos and images, input data will be resized
    | | +| [202-vision-superresolution-image](202-vision-superresolution/202-vision-superresolution-image.ipynb) |
    • Demonstrates how to use [single-image-super-resolution-1032](https://docs.openvinotoolkit.org/latest/omz_models_model_single_image_super_resolution_1032.html) from Open Model Zoo
    • A raw image is provided and upscaled
    • Users can upload their own raw images and try upscaling
    | | +| [202-vision-superresolution-video](202-vision-superresolution/202-vision-superresolution-video.ipynb) |
    • Same as previous notebook, but upscales video instead of just an image
    • Users can upload their own video files to try upscaling
    | | +| [205-vision-background-removal](205-vision-background-removal/205-vision-background-removal.ipynb) |
    • Demonstrates background removal in images
    • The open source [U^2-Net](https://github.com/xuebinqin/U-2-Net) model is converted from PyTorch
    • Users can upload their own images to remove and replace the background with OpenVINO and OpenCV
    | | +| [206-vision-paddlegan-anime](206-vision-paddlegan-anime/206-vision-paddlegan-anime.ipynb) |
    • Demonstrates using PaddlePaddle models with OpenVINO
    • The open source [AnimeGAN](https://github.com/PaddlePaddle/PaddleGAN) model is converted with paddle2onnx and then OpenVINO IR with Model Optimizer
    • Shows inference results on the AnimeGAN model
    • Benchmark app shows performance on CPU, iGPU and both devices together using [MULTI plugin](https://docs.openvinotoolkit.org/latest/openvino_docs_IE_DG_supported_plugins_MULTI.html)
    • Users can upload their own images to try out
    | | +| [301-tensorflow-training-openvino](301-tensorflow-training-openvino/301-tensorflow-training-openvino.ipynb) |
    • Demonstrates end-to-end training to deployment workflow starting with TensorFlow’s Flowers classification demo
    • Downloads flowers dataset, download keras model, train 10 epochs on CPU, test trained model, convert to OpenVINO IR and test IR performance
    | `This image most likely belongs to dandelion with a 99.02 percent confidence.`
    | +| [301-tensorflow-training-openvino-pot](301-tensorflow-training-openvino/301-tensorflow-training-openvino-pot.ipynb) |
    • Demonstrates post-training quantization with flower IR model from previous notebook
    • Uses [Post Training Optimization Tool](https://docs.openvinotoolkit.org/latest/pot_README.html) from OpenVINO with default quantization method
    • Shows benchmark app performance on CPU, iGPU and MULTI:CPU,GPU
    | `This image most likely belongs to dandelion with a 99.08 percent confidence.`
    | From f4a70d68736ee09157050ca928c4351bbcb5d392 Mon Sep 17 00:00:00 2001 From: Helena Kloosterman Date: Tue, 13 Jul 2021 15:04:51 +0200 Subject: [PATCH 14/21] Add Launch Binder buttons to notebooks README (#169) - Add Launch Binder button for supported notebooks - Fix link to fastseg model --- notebooks/README.md | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/notebooks/README.md b/notebooks/README.md index ca4a7c200c5..4c2e033f48f 100644 --- a/notebooks/README.md +++ b/notebooks/README.md @@ -1,19 +1,24 @@ ## List of Notebooks -Each notebook is located in a directory. Please follow the instructions in the [README](https://github.com/openvinotoolkit/openvino_notebooks/) before launching Jupyter Lab or Jupyter Notebook. +Each notebook is located in a directory. Please follow the instructions in the +[README](https://github.com/openvinotoolkit/openvino_notebooks/) before launching Jupyter Lab or +Jupyter Notebook. +Notebooks that have a ![](https://mybinder.org/badge_logo.svg) button can be +opened in [Binder](https://mybinder.org/), to try the notebooks without installing anything. Binder is a free online service with limited resources. For better performance, it is recommended to install the notebooks locally by following the instructions in the +[README](https://github.com/openvinotoolkit/openvino_notebooks/). | Notebook | Description | Preview | | :---: | :--- | :----: | -| [001-hello-world](001-hello-world/001-hello-world.ipynb) |
    • A very basic introduction to OpenVINO's [Python API](https://docs.openvinotoolkit.org/latest/ie_python_api/annotated.html)
    • Shows how to do inference on a [mobilenetv3](https://docs.openvinotoolkit.org/latest/omz_models_model_mobilenet_v3_small_1_0_224_tf.html) image classification model
    |
    `['n02099267', 'flat-coated_retriever']` | -| [002-openvino-api](002-openvino-api/002-openvino-api.ipynb) | OpenVINO API tutorial that covers the following:
    • Load Inference Engine and Show Info
    • Loading a Model
      • IR Model
      • ONNX Model
    • Getting Information about a Model
      • Model Inputs
      • Model Outputs
    • Doing Inference on a Model
    • Reshaping and Resizing
      • Change Image Size
      • Change Batch Size
    | | -| [101-tensorflow-to-openvino](101-tensorflow-to-openvino/101-tensorflow-to-openvino.ipynb) |
    • Demonstrates how to convert [TensorFlow](https://www.tensorflow.org/) models to OpenVINO IR
    • Uses Model Optimizer to convert the same [mobilenetv3](https://docs.openvinotoolkit.org/latest/omz_models_model_mobilenet_v3_small_1_0_224_tf.html) image classification model from `001-hello-world` notebook
    |
    `['n02099267', 'flat-coated_retriever']` | -| [102-pytorch-onnx-to-openvino](102-pytorch-onnx-to-openvino/102-pytorch-onnx-to-openvino.ipynb) |
    • Demonstrates how to convert [PyTorch](https://pytorch.org/) models to OpenVINO IR
    • Uses Model Optimizer to convert the open source [fastseg](https://docs.openvinotoolkit.org/latest/omz_models_model_mobilenet_v3_small_1_0_224_tf.html) semantic segmentation model
    | | -| [104-model-tools](104-model-tools/104-model-tools.ipynb) |
    • Demonstrates how to download a model from Open Model Zoo, convert it to OpenVINO's IR format, show information about the model, and asynchronously benchmark the model on CPU, iGPU and both devices combined. | | -| [201-vision-monodepth](201-vision-monodepth/201-vision-monodepth.ipynb) |
      • Demonstrates Monocular Depth Estimation with MidasNet model in OpenVINO
      • Uses [OpenCV](https://opencv.org/) to load and process frames from an image and a video
      • Generates output video showing input and output side by side
      • Users can upload their own videos and images, input data will be resized
      | | -| [202-vision-superresolution-image](202-vision-superresolution/202-vision-superresolution-image.ipynb) |
      • Demonstrates how to use [single-image-super-resolution-1032](https://docs.openvinotoolkit.org/latest/omz_models_model_single_image_super_resolution_1032.html) from Open Model Zoo
      • A raw image is provided and upscaled
      • Users can upload their own raw images and try upscaling
      | | -| [202-vision-superresolution-video](202-vision-superresolution/202-vision-superresolution-video.ipynb) |
      • Same as previous notebook, but upscales video instead of just an image
      • Users can upload their own video files to try upscaling
      | | -| [205-vision-background-removal](205-vision-background-removal/205-vision-background-removal.ipynb) |
      • Demonstrates background removal in images
      • The open source [U^2-Net](https://github.com/xuebinqin/U-2-Net) model is converted from PyTorch
      • Users can upload their own images to remove and replace the background with OpenVINO and OpenCV
      | | +| [001-hello-world](001-hello-world/001-hello-world.ipynb)

      [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/openvinotoolkit/openvino_notebooks/HEAD?filepath=notebooks%2F001-hello-world%2F001-hello-world.ipynb) |
      • A very basic introduction to OpenVINO's [Python API](https://docs.openvinotoolkit.org/latest/ie_python_api/annotated.html)
      • Shows how to do inference on a [mobilenetv3](https://docs.openvinotoolkit.org/latest/omz_models_model_mobilenet_v3_small_1_0_224_tf.html) image classification model
      |
      `['n02099267', 'flat-coated_retriever']` | +| [002-openvino-api](002-openvino-api/002-openvino-api.ipynb)

      [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/openvinotoolkit/openvino_notebooks/HEAD?filepath=notebooks%2F002-openvino-api%2F002-openvino-api.ipynb) | OpenVINO API tutorial that covers the following:
      • Load Inference Engine and Show Info
      • Loading a Model
        • IR Model
        • ONNX Model
      • Getting Information about a Model
        • Model Inputs
        • Model Outputs
      • Doing Inference on a Model
      • Reshaping and Resizing
        • Change Image Size
        • Change Batch Size
      | | +| [101-tensorflow-to-openvino](101-tensorflow-to-openvino/101-tensorflow-to-openvino.ipynb)

      [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/openvinotoolkit/openvino_notebooks/HEAD?filepath=notebooks%2F101-tensorflow-to-openvino%2F101-tensorflow-to-openvino.ipynb) |
      • Demonstrates how to convert [TensorFlow](https://www.tensorflow.org/) models to OpenVINO IR
      • Uses Model Optimizer to convert the same [mobilenetv3](https://docs.openvinotoolkit.org/latest/omz_models_model_mobilenet_v3_small_1_0_224_tf.html) image classification model from `001-hello-world` notebook
      |
      `['n02099267', 'flat-coated_retriever']` | +| [102-pytorch-onnx-to-openvino](102-pytorch-onnx-to-openvino/102-pytorch-onnx-to-openvino.ipynb) |
      • Demonstrates how to convert [PyTorch](https://pytorch.org/) models to OpenVINO IR
      • Uses Model Optimizer to convert the open source [fastseg](https://github.com/ekzhang/fastseg/) semantic segmentation model
      | | +| [104-model-tools](104-model-tools/104-model-tools.ipynb)

      [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/openvinotoolkit/openvino_notebooks/HEAD?filepath=notebooks%2F104-model-tools%2F104-model-tools.ipynb) |
      • Demonstrates how to download a model from Open Model Zoo, convert it to OpenVINO's IR format, show information about the model, and asynchronously benchmark the model on CPU, iGPU and both devices combined. | | +| [201-vision-monodepth](201-vision-monodepth/201-vision-monodepth.ipynb)

        [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/openvinotoolkit/openvino_notebooks/HEAD?filepath=notebooks%2F201-vision-monodepth%2F201-vision-monodepth.ipynb) |
        • Demonstrates Monocular Depth Estimation with MidasNet model in OpenVINO
        • Uses [OpenCV](https://opencv.org/) to load and process frames from an image and a video
        • Generates output video showing input and output side by side
        • Users can upload their own videos and images, input data will be resized
        | | +| [202-vision-superresolution-image](202-vision-superresolution/202-vision-superresolution-image.ipynb)

        [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/openvinotoolkit/openvino_notebooks/HEAD?filepath=notebooks%2F202-vision-superresolution%2F202-vision-superresolution-image.ipynb)|
        • Demonstrates how to use [single-image-super-resolution-1032](https://docs.openvinotoolkit.org/latest/omz_models_model_single_image_super_resolution_1032.html) from Open Model Zoo
        • A raw image is provided and upscaled
        • Users can upload their own raw images and try upscaling
        | | +| [202-vision-superresolution-video](202-vision-superresolution/202-vision-superresolution-video.ipynb)

        [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/openvinotoolkit/openvino_notebooks/HEAD?filepath=notebooks%2F202-vision-superresolution%2F202-vision-superresolution-video.ipynb) |
        • Same as previous notebook, but upscales video instead of just an image
        • Users can upload their own video files to try upscaling
        | | +| [205-vision-background-removal](205-vision-background-removal/205-vision-background-removal.ipynb)

        [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/openvinotoolkit/openvino_notebooks/HEAD?filepath=notebooks%2F205-vision-background-removal%2F205-vision-background-removal.ipynb) |
        • Demonstrates background removal in images
        • The open source [U^2-Net](https://github.com/xuebinqin/U-2-Net) model is converted from PyTorch
        • Users can upload their own images to remove and replace the background with OpenVINO and OpenCV
        | | | [206-vision-paddlegan-anime](206-vision-paddlegan-anime/206-vision-paddlegan-anime.ipynb) |
        • Demonstrates using PaddlePaddle models with OpenVINO
        • The open source [AnimeGAN](https://github.com/PaddlePaddle/PaddleGAN) model is converted with paddle2onnx and then OpenVINO IR with Model Optimizer
        • Shows inference results on the AnimeGAN model
        • Benchmark app shows performance on CPU, iGPU and both devices together using [MULTI plugin](https://docs.openvinotoolkit.org/latest/openvino_docs_IE_DG_supported_plugins_MULTI.html)
        • Users can upload their own images to try out
        | | | [301-tensorflow-training-openvino](301-tensorflow-training-openvino/301-tensorflow-training-openvino.ipynb) |
        • Demonstrates end-to-end training to deployment workflow starting with TensorFlow’s Flowers classification demo
        • Downloads flowers dataset, download keras model, train 10 epochs on CPU, test trained model, convert to OpenVINO IR and test IR performance
        | `This image most likely belongs to dandelion with a 99.02 percent confidence.`
        | | [301-tensorflow-training-openvino-pot](301-tensorflow-training-openvino/301-tensorflow-training-openvino-pot.ipynb) |
        • Demonstrates post-training quantization with flower IR model from previous notebook
        • Uses [Post Training Optimization Tool](https://docs.openvinotoolkit.org/latest/pot_README.html) from OpenVINO with default quantization method
        • Shows benchmark app performance on CPU, iGPU and MULTI:CPU,GPU
        | `This image most likely belongs to dandelion with a 99.08 percent confidence.`
        | From f7ab2473c93ce18838ecc61dc53a150d4e51d753 Mon Sep 17 00:00:00 2001 From: Helena Kloosterman Date: Tue, 13 Jul 2021 15:05:12 +0200 Subject: [PATCH 15/21] Replace Tensorflow with TensorFlow (#171) --- .docker/requirements.in | 2 +- notebooks/001-hello-world/001-hello-world.ipynb | 2 +- notebooks/002-openvino-api/002-openvino-api.ipynb | 2 +- .../101-tensorflow-to-openvino.ipynb | 2 +- .../301-tensorflow-training-openvino.ipynb | 12 ++++++------ 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.docker/requirements.in b/.docker/requirements.in index ef8abe32cb0..e73e826f90e 100644 --- a/.docker/requirements.in +++ b/.docker/requirements.in @@ -21,7 +21,7 @@ ipywidgets torch>=1.5.1+cpu,<=1.7.1+cpu torchvision>=0.6.1+cpu,<=0.8.2+cpu -# Tensorflow notebook requirements +# TensorFlow notebook requirements networkx>=1.11 defusedxml>=0.5.0 tensorflow==2.4.2 diff --git a/notebooks/001-hello-world/001-hello-world.ipynb b/notebooks/001-hello-world/001-hello-world.ipynb index 96dc1f24110..b8cf082aa70 100644 --- a/notebooks/001-hello-world/001-hello-world.ipynb +++ b/notebooks/001-hello-world/001-hello-world.ipynb @@ -9,7 +9,7 @@ "\n", "A very basic introduction to OpenVINO that shows how to do inference on a given IR model.\n", "\n", - "We use a [MobileNetV3 model](https://docs.openvinotoolkit.org/latest/omz_models_model_mobilenet_v3_small_1_0_224_tf.html) from [Open Model Zoo](https://github.com/openvinotoolkit/open_model_zoo/). See the [Tensorflow to OpenVINO Notebook](101-tensorflow-to-openvino) for information on how this OpenVINO IR model was created.\n", + "We use a [MobileNetV3 model](https://docs.openvinotoolkit.org/latest/omz_models_model_mobilenet_v3_small_1_0_224_tf.html) from [Open Model Zoo](https://github.com/openvinotoolkit/open_model_zoo/). See the [TensorFlow to OpenVINO Notebook](101-tensorflow-to-openvino) for information on how this OpenVINO IR model was created.\n", "\n" ] }, diff --git a/notebooks/002-openvino-api/002-openvino-api.ipynb b/notebooks/002-openvino-api/002-openvino-api.ipynb index ec10ce87669..82af7dd46dc 100644 --- a/notebooks/002-openvino-api/002-openvino-api.ipynb +++ b/notebooks/002-openvino-api/002-openvino-api.ipynb @@ -88,7 +88,7 @@ "\n", "An IR (Intermediate Representation) model consists of an .xml file, containing model information, and a .bin file, containing the weights. `read_network()` expects the weights file to be located in the same directory as the xml file, with the same filename, and the extension .bin: `model_weights_file == Path(model_xml).with_suffix(\".bin\")`. If this is the case, specifying the weights file is optional. If the weights file has a different filename, it can be specified with the `weights` parameter to `read_network()`.\n", "\n", - "See the [tensorflow-to-openvino](../101-tensorflow-to-openvino/101-tensorflow-to-openvino.ipynb) and [pytorch-onnx-to-openvino](../102-pytorch-onnx-to-openvino/102-pytorch-onnx-to-openvino.ipynb) notebooks for information on how to convert your existing Tensorflow, PyTorch or ONNX model to OpenVINO's IR format." + "See the [tensorflow-to-openvino](../101-tensorflow-to-openvino/101-tensorflow-to-openvino.ipynb) and [pytorch-onnx-to-openvino](../102-pytorch-onnx-to-openvino/102-pytorch-onnx-to-openvino.ipynb) notebooks for information on how to convert your existing TensorFlow, PyTorch or ONNX model to OpenVINO's IR format." ] }, { diff --git a/notebooks/101-tensorflow-to-openvino/101-tensorflow-to-openvino.ipynb b/notebooks/101-tensorflow-to-openvino/101-tensorflow-to-openvino.ipynb index b151d874146..c40f94554df 100644 --- a/notebooks/101-tensorflow-to-openvino/101-tensorflow-to-openvino.ipynb +++ b/notebooks/101-tensorflow-to-openvino/101-tensorflow-to-openvino.ipynb @@ -6,7 +6,7 @@ "id": "JwEAhQVzkAwA" }, "source": [ - "# Tensorflow to OpenVINO\n", + "# TensorFlow to OpenVINO\n", "\n", "This short tutorial shows how to convert a TensorFlow MobilenetV3 model to OpenVINO IR format.\n", "Model documentation: https://docs.openvinotoolkit.org/latest/omz_models_model_mobilenet_v3_small_1_0_224_tf.html" diff --git a/notebooks/301-tensorflow-training-openvino/301-tensorflow-training-openvino.ipynb b/notebooks/301-tensorflow-training-openvino/301-tensorflow-training-openvino.ipynb index 4b8ce32188b..110b1e41ee0 100644 --- a/notebooks/301-tensorflow-training-openvino/301-tensorflow-training-openvino.ipynb +++ b/notebooks/301-tensorflow-training-openvino/301-tensorflow-training-openvino.ipynb @@ -27,11 +27,11 @@ "id": "KwQtSOz0VrVX" }, "source": [ - "## From Training to Deployment with Tensorflow and OpenVINO \n", + "## From Training to Deployment with TensorFlow and OpenVINO \n", "\n", - "This example demonstrates how to train, convert, and deploy an image classification model with Tensorflow and OpenVINO. This particular notebook shows the process where we perform the inference step on the freshly trained model. \n", + "This example demonstrates how to train, convert, and deploy an image classification model with TensorFlow and OpenVINO. This particular notebook shows the process where we perform the inference step on the freshly trained model. \n", "\n", - "The training code is based on the official Tensorflow Image Classification Tutorial: (https://www.tensorflow.org/tutorials/images/classification).\n", + "The training code is based on the official TensorFlow Image Classification Tutorial: (https://www.tensorflow.org/tutorials/images/classification).\n", "\n", "The **flower_ir.bin** and **flower_ir.xml** (pre-trained models) can be obtained by executing the code with 'Runtime->Run All' or the Ctrl+F9 command. \n" ] @@ -40,7 +40,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Tensorflow Image Classification Training" + "## TensorFlow Image Classification Training" ] }, { @@ -49,7 +49,7 @@ "id": "gN7G9GFmVrVY" }, "source": [ - "The first part of the tutorial shows how to classify images of flowers (based on the Tensorflow's official tutorial). It creates an image classifier using a `keras.Sequential` model, and loads data using `preprocessing.image_dataset_from_directory`. You will gain practical experience with the following concepts:\n", + "The first part of the tutorial shows how to classify images of flowers (based on the TensorFlow's official tutorial). It creates an image classifier using a `keras.Sequential` model, and loads data using `preprocessing.image_dataset_from_directory`. You will gain practical experience with the following concepts:\n", "\n", "* Efficiently loading a dataset off disk.\n", "* Identifying overfitting and applying techniques to mitigate it, including data augmentation and Dropout.\n", @@ -959,7 +959,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Save the Tensorflow Model" + "## Save the TensorFlow Model" ] }, { From 4a7bdcab4f677c4eb27021330246f36cb5b47549 Mon Sep 17 00:00:00 2001 From: Helena Kloosterman Date: Wed, 14 Jul 2021 11:19:35 +0200 Subject: [PATCH 16/21] Set log_level to CRITICAL in MO for 205 (#172) --- .../205-vision-background-removal.ipynb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/notebooks/205-vision-background-removal/205-vision-background-removal.ipynb b/notebooks/205-vision-background-removal/205-vision-background-removal.ipynb index 4f4c9783247..f766be0b34a 100644 --- a/notebooks/205-vision-background-removal/205-vision-background-removal.ipynb +++ b/notebooks/205-vision-background-removal/205-vision-background-removal.ipynb @@ -276,6 +276,7 @@ "mo_path = str(Path(mo_onnx.__file__))\n", "\n", "# Construct the command for Model Optimizer\n", + "# Set log_level to CRITICAL to suppress warnings that can be ignored for this demo\n", "mo_command = f\"\"\"\"{sys.executable}\"\n", " \"{mo_path}\"\n", " --input_model \"{onnx_path}\"\n", @@ -284,6 +285,7 @@ " --scale_values=\"[58.395, 57.12 , 57.375]\"\n", " --data_type FP16\n", " --output_dir \"{model_path.parent}\"\n", + " --log_level \"CRITICAL\"\n", " \"\"\"\n", "mo_command = \" \".join(mo_command.split())\n", "print(\"Model Optimizer command to convert the ONNX model to OpenVINO:\")\n", From 5f68c39bad5f829c061fa93687db240eeb1c619a Mon Sep 17 00:00:00 2001 From: Helena Kloosterman Date: Wed, 14 Jul 2021 11:19:48 +0200 Subject: [PATCH 17/21] Make AnimeGAN inference optional on PaddlePaddle model (#170) Add PADDLEGAN_INFERENCE setting. Default True, if set to False, inference on PaddlePaddle model will be skipped. This allows running the notebook on systems with limited resources, and speeds up "Run All Cells" if you are not interested in comparisons with the original PaddleGAN model but just want to quickly show the notebook. --- .../206-vision-paddlegan-anime.ipynb | 78 +++++++++++-------- 1 file changed, 45 insertions(+), 33 deletions(-) diff --git a/notebooks/206-vision-paddlegan-anime/206-vision-paddlegan-anime.ipynb b/notebooks/206-vision-paddlegan-anime/206-vision-paddlegan-anime.ipynb index c6366545e0d..acc2ee6e73a 100644 --- a/notebooks/206-vision-paddlegan-anime/206-vision-paddlegan-anime.ipynb +++ b/notebooks/206-vision-paddlegan-anime/206-vision-paddlegan-anime.ipynb @@ -190,7 +190,7 @@ "6. optionally adjusts the brightness of the result image\n", "7. saves the image\n", "\n", - "We can execute these steps manually and confirm that the result looks correct. To speed up inference time, resize large images before propagating them through the network. The inference step in the next cell will still take some time to execute." + "We can execute these steps manually and confirm that the result looks correct. To speed up inference time, resize large images before propagating them through the network. The inference step in the next cell will still take some time to execute. If you want to skip this step, set `PADDLEGAN_INFERENCE = False` in the first line of the next cell." ] }, { @@ -200,6 +200,8 @@ "metadata": {}, "outputs": [], "source": [ + "PADDLEGAN_INFERENCE = True\n", + "\n", "# Step 1. Load the image and convert to RGB\n", "image_path = Path(\"coco_bricks.png\")\n", "\n", @@ -212,26 +214,27 @@ "transformed_image = predictor.transform(image)\n", "input_tensor = paddle.to_tensor(transformed_image[None, ::])\n", "\n", - "# Step 3. Do inference. \n", - "predictor.generator.eval()\n", - "with paddle.no_grad():\n", - " result = predictor.generator(input_tensor)\n", + "if PADDLEGAN_INFERENCE:\n", + " # Step 3. Do inference. \n", + " predictor.generator.eval()\n", + " with paddle.no_grad():\n", + " result = predictor.generator(input_tensor)\n", "\n", - "# Step 4. Convert the inference result to an image following the same steps as\n", - "# PaddleGAN's predictor.run() function\n", - "result_image_pg = (result * 0.5 + 0.5)[0].numpy() * 255\n", - "result_image_pg = result_image_pg.transpose((1, 2, 0))\n", + " # Step 4. Convert the inference result to an image following the same steps as\n", + " # PaddleGAN's predictor.run() function\n", + " result_image_pg = (result * 0.5 + 0.5)[0].numpy() * 255\n", + " result_image_pg = result_image_pg.transpose((1, 2, 0))\n", "\n", - "# Step 5. Resize the result image\n", - "result_image_pg = cv2.resize(result_image_pg, image.shape[:2][::-1])\n", + " # Step 5. Resize the result image\n", + " result_image_pg = cv2.resize(result_image_pg, image.shape[:2][::-1])\n", "\n", - "# Step 6. Adjust the brightness\n", - "result_image_pg = predictor.adjust_brightness(result_image_pg, image)\n", + " # Step 6. Adjust the brightness\n", + " result_image_pg = predictor.adjust_brightness(result_image_pg, image)\n", "\n", - "# Step 7. Save the result image\n", - "anime_image_path_pg = image_path.with_name(image_path.stem + \"_anime_pg\").with_suffix(\".jpg\")\n", - "if cv2.imwrite(str(anime_image_path_pg), result_image_pg[:, :, (2, 1, 0)]):\n", - " print(f\"The anime image was saved to {anime_image_path_pg}\")" + " # Step 7. Save the result image\n", + " anime_image_path_pg = image_path.with_name(image_path.stem + \"_anime_pg\").with_suffix(\".jpg\")\n", + " if cv2.imwrite(str(anime_image_path_pg), result_image_pg[:, :, (2, 1, 0)]):\n", + " print(f\"The anime image was saved to {anime_image_path_pg}\")" ] }, { @@ -249,9 +252,12 @@ "metadata": {}, "outputs": [], "source": [ - "fig, ax = plt.subplots(1, 2, figsize=(25, 15))\n", - "ax[0].imshow(image)\n", - "ax[1].imshow(result_image_pg)" + "if PADDLEGAN_INFERENCE:\n", + " fig, ax = plt.subplots(1, 2, figsize=(25, 15))\n", + " ax[0].imshow(image)\n", + " ax[1].imshow(result_image_pg)\n", + "else:\n", + " print(\"PADDLEGAN_INFERENCE is not enabled. Set PADDLEGAN_INFERENCE = True in the previous cell and run that cell to show inference results.\")" ] }, { @@ -350,7 +356,7 @@ "the minimum size to resize to. The ResizeToScale transform resizes images to the size specified in the\n", "ResizeToScale params, with width and height as multiples of 32.\n", "\n", - "Now that we know the mean and standard deviation values, and the shape of the model inputs, we can call Model Optimizer and convert the model to IR with these values. " + "Now that we know the mean and standard deviation values, and the shape of the model inputs, we can call Model Optimizer and convert the model to IR with these values. We use FP16 precision and set log level to CRITICAL to ignore warnings that are irrelevant for this demo. See the [Model Optimizer Documentation](https://docs.openvinotoolkit.org/latest/openvino_docs_MO_DG_prepare_model_convert_model_Converting_Model_General.html) for information about Model Optimizer parameters." ] }, { @@ -372,7 +378,7 @@ "python = sys.executable\n", "onnx_path = model_path.with_suffix(\".onnx\")\n", "print(\"Exporting ONNX model to IR... This may take a few minutes.\")\n", - "! $python $mo --input_model $onnx_path --input_shape [1,3,$target_height,$target_width] --model_name $MODEL_NAME --data_type \"FP16\" --mean_values=\"[127.5,127.5,127.5]\" --scale_values=\"[127.5,127.5,127.5]\"" + "! $python $mo --input_model $onnx_path --input_shape [1,3,$target_height,$target_width] --model_name $MODEL_NAME --data_type \"FP16\" --mean_values=\"[127.5,127.5,127.5]\" --scale_values=\"[127.5,127.5,127.5]\" --log_level \"CRITICAL\"" ] }, { @@ -590,17 +596,23 @@ "# else:\n", "# print(\"A supported iGPU device is not available on this system.\")\n", "\n", - "\n", - "with paddle.no_grad():\n", - " start = time.perf_counter()\n", - " for _ in range(NUM_IMAGES):\n", - " predictor.generator(input_tensor)\n", - " end = time.perf_counter()\n", - " time_paddle = end - start\n", - "print(\n", - " f\"PaddleGAN model on CPU: {time_paddle/NUM_IMAGES:.3f} seconds per image, \"\n", - " f\"FPS: {NUM_IMAGES/time_paddle:.2f}\"\n", - ")" + "## PADDLEGAN_INFERENCE is defined in the section \"Inference on PaddleGAN model\"\n", + "## Uncomment the next line to enable a performance comparison with the PaddleGAN model \n", + "## if you disabled it earlier. \n", + "\n", + "# PADDLEGAN_INFERENCE = True\n", + "\n", + "if PADDLEGAN_INFERENCE:\n", + " with paddle.no_grad():\n", + " start = time.perf_counter()\n", + " for _ in range(NUM_IMAGES):\n", + " predictor.generator(input_tensor)\n", + " end = time.perf_counter()\n", + " time_paddle = end - start\n", + " print(\n", + " f\"PaddleGAN model on CPU: {time_paddle/NUM_IMAGES:.3f} seconds per image, \"\n", + " f\"FPS: {NUM_IMAGES/time_paddle:.2f}\"\n", + " )" ] }, { From 9cb21b128758b8955df66c2d5da8bc5589f41c67 Mon Sep 17 00:00:00 2001 From: Helena Kloosterman Date: Thu, 15 Jul 2021 14:31:55 +0200 Subject: [PATCH 18/21] Show device names in 104 notebook (#175) --- notebooks/104-model-tools/104-model-tools.ipynb | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/notebooks/104-model-tools/104-model-tools.ipynb b/notebooks/104-model-tools/104-model-tools.ipynb index 1890cba4bf8..cf78282edd7 100644 --- a/notebooks/104-model-tools/104-model-tools.ipynb +++ b/notebooks/104-model-tools/104-model-tools.ipynb @@ -325,7 +325,7 @@ "\n", "Run `! benchmark_app --help` to get an overview of all possible command line parameters.\n", "\n", - "In the next cell, we define a `benchmark_model()` function that calls `benchmark_app`. This makes it easy to try different combinations." + "In the next cell, we define a `benchmark_model()` function that calls `benchmark_app`. This makes it easy to try different combinations. In the cell below that, we display the available devices on the system." ] }, { @@ -350,6 +350,21 @@ " print(\"\\n\".join(benchmark_result))" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "298904f0-638c-4958-876a-3b8c8bd06518", + "metadata": {}, + "outputs": [], + "source": [ + "ie = IECore()\n", + "\n", + "# Show devices available for OpenVINO Inference Engine\n", + "for device in ie.available_devices:\n", + " device_name = ie.get_metric(device, \"FULL_DEVICE_NAME\")\n", + " print(f\"{device}: {device_name}\")" + ] + }, { "cell_type": "code", "execution_count": null, From 8af9668bb31c84a121365a863dc444fd49322487 Mon Sep 17 00:00:00 2001 From: Helena Kloosterman Date: Thu, 15 Jul 2021 14:32:50 +0200 Subject: [PATCH 19/21] Add Binder button for PaddleGAN notebook (#174) * Add Binder button for PaddleGAN notebook Change PADDLEGAN_INFERENCE setting in notebook in Binder image to allow it to work without manually setting this setting. PaddleGAN inference takes too much memory for Binder. * Delete 301 and 102 notebooks from Binder --- .binder/postBuild | 3 ++- notebooks/README.md | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.binder/postBuild b/.binder/postBuild index c35a7ef9574..248af6df65b 100644 --- a/.binder/postBuild +++ b/.binder/postBuild @@ -1,3 +1,4 @@ rm -rf notebooks/102-pytorch-onnx-to-openvino -rm -rf notebooks/206-vision-paddlegan-anime rm -rf notebooks/301-tensorflow-training-openvino + +sed -i 's/"PADDLEGAN_INFERENCE = True/"PADDLEGAN_INFERENCE = False/' notebooks/206-vision-paddlegan-anime/206-vision-paddlegan-anime.ipynb diff --git a/notebooks/README.md b/notebooks/README.md index 4c2e033f48f..f10206d269d 100644 --- a/notebooks/README.md +++ b/notebooks/README.md @@ -19,6 +19,6 @@ opened in [Binder](https://mybinder.org/), to try the notebooks without installi | [202-vision-superresolution-image](202-vision-superresolution/202-vision-superresolution-image.ipynb)

        [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/openvinotoolkit/openvino_notebooks/HEAD?filepath=notebooks%2F202-vision-superresolution%2F202-vision-superresolution-image.ipynb)|
        • Demonstrates how to use [single-image-super-resolution-1032](https://docs.openvinotoolkit.org/latest/omz_models_model_single_image_super_resolution_1032.html) from Open Model Zoo
        • A raw image is provided and upscaled
        • Users can upload their own raw images and try upscaling
        | | | [202-vision-superresolution-video](202-vision-superresolution/202-vision-superresolution-video.ipynb)

        [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/openvinotoolkit/openvino_notebooks/HEAD?filepath=notebooks%2F202-vision-superresolution%2F202-vision-superresolution-video.ipynb) |
        • Same as previous notebook, but upscales video instead of just an image
        • Users can upload their own video files to try upscaling
        | | | [205-vision-background-removal](205-vision-background-removal/205-vision-background-removal.ipynb)

        [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/openvinotoolkit/openvino_notebooks/HEAD?filepath=notebooks%2F205-vision-background-removal%2F205-vision-background-removal.ipynb) |
        • Demonstrates background removal in images
        • The open source [U^2-Net](https://github.com/xuebinqin/U-2-Net) model is converted from PyTorch
        • Users can upload their own images to remove and replace the background with OpenVINO and OpenCV
        | | -| [206-vision-paddlegan-anime](206-vision-paddlegan-anime/206-vision-paddlegan-anime.ipynb) |
        • Demonstrates using PaddlePaddle models with OpenVINO
        • The open source [AnimeGAN](https://github.com/PaddlePaddle/PaddleGAN) model is converted with paddle2onnx and then OpenVINO IR with Model Optimizer
        • Shows inference results on the AnimeGAN model
        • Benchmark app shows performance on CPU, iGPU and both devices together using [MULTI plugin](https://docs.openvinotoolkit.org/latest/openvino_docs_IE_DG_supported_plugins_MULTI.html)
        • Users can upload their own images to try out
        | | +| [206-vision-paddlegan-anime](206-vision-paddlegan-anime/206-vision-paddlegan-anime.ipynb)

        [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/openvinotoolkit/openvino_notebooks/HEAD?filepath=notebooks%2F206-vision-paddlegan-anime%2F206-vision-paddlegan-anime.ipynb) |
        • Demonstrates using PaddlePaddle models with OpenVINO
        • The open source [AnimeGAN](https://github.com/PaddlePaddle/PaddleGAN) model is converted with paddle2onnx and then OpenVINO IR with Model Optimizer
        • Shows inference results on the AnimeGAN model
        • Benchmark app shows performance on CPU, iGPU and both devices together using [MULTI plugin](https://docs.openvinotoolkit.org/latest/openvino_docs_IE_DG_supported_plugins_MULTI.html)
        • Users can upload their own images to try out
        | | | [301-tensorflow-training-openvino](301-tensorflow-training-openvino/301-tensorflow-training-openvino.ipynb) |
        • Demonstrates end-to-end training to deployment workflow starting with TensorFlow’s Flowers classification demo
        • Downloads flowers dataset, download keras model, train 10 epochs on CPU, test trained model, convert to OpenVINO IR and test IR performance
        | `This image most likely belongs to dandelion with a 99.02 percent confidence.`
        | | [301-tensorflow-training-openvino-pot](301-tensorflow-training-openvino/301-tensorflow-training-openvino-pot.ipynb) |
        • Demonstrates post-training quantization with flower IR model from previous notebook
        • Uses [Post Training Optimization Tool](https://docs.openvinotoolkit.org/latest/pot_README.html) from OpenVINO with default quantization method
        • Shows benchmark app performance on CPU, iGPU and MULTI:CPU,GPU
        | `This image most likely belongs to dandelion with a 99.08 percent confidence.`
        | From fdb298c7e7efba675633bebac855f1b0b9a42af7 Mon Sep 17 00:00:00 2001 From: Helena Kloosterman Date: Thu, 15 Jul 2021 14:33:43 +0200 Subject: [PATCH 20/21] Add note about C++ requirement to README.md (#173) --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5d322e8ff84..78ea77e0592 100644 --- a/README.md +++ b/README.md @@ -20,12 +20,12 @@ The notebooks run almost anywhere — your laptop, a cloud VM, or even a Doc ## 📝 Installation Guide -OpenVINO Notebooks require Python and Git. See instructions below for your operating system: +OpenVINO Notebooks require Python and Git. For Python 3.8, C++ is also required. See instructions below for your operating system: | [Windows 10](https://github.com/openvinotoolkit/openvino_notebooks/wiki/Windows) | [Ubuntu](https://github.com/openvinotoolkit/openvino_notebooks/wiki/Ubuntu) | [macOS](https://github.com/openvinotoolkit/openvino_notebooks/wiki/macOS) | [Red Hat](https://github.com/openvinotoolkit/openvino_notebooks/wiki/Red-Hat-and-CentOS) | [CentOS](https://github.com/openvinotoolkit/openvino_notebooks/wiki/Red-Hat-and-CentOS) | [Azure ML](https://github.com/openvinotoolkit/openvino_notebooks/wiki/AzureML) | | -------------------------------------------------------------------------------- | --------------------------------------------------------------------------- | ------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------ | -Once you have installed Python and Git, follow the steps below. +Once you have installed Python, Git and C++, follow the steps below. ### Step 1: Create and Activate `openvino_env` Environment From 811c3c72cc54272933febf7de2230570db47f463 Mon Sep 17 00:00:00 2001 From: Helena Kloosterman Date: Fri, 16 Jul 2021 20:06:25 +0200 Subject: [PATCH 21/21] Run docker test on notebooks change (#176) --- .github/workflows/docker.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 3087083d5cf..bcf1446f0d1 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -7,6 +7,10 @@ on: - "Dockerfile" - ".docker/**" - ".github/workflows/docker.yml" + - 'notebooks/**.ipynb' + - 'notebooks/**.py' + - 'requirements.txt' + - '.ci/*requirements.txt' jobs: build: