Skip to content

Commit

Permalink
fix code style
Browse files Browse the repository at this point in the history
  • Loading branch information
eaidova committed Aug 26, 2024
1 parent 132950a commit 4fc3e73
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .ci/patch_notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
EXCLUDED_NOTEBOOKS = ["data-preparation-ct-scan.ipynb", "pytorch-monai-training.ipynb"]

DEVICE_WIDGET = "device = widgets.Dropdown("
DEVICE_WIDGET_NEW = "device = device_widget("
DEVICE_WIDGET_NEW = "device_widget("


def disable_gradio_debug(nb, notebook_path):
Expand Down
12 changes: 4 additions & 8 deletions notebooks/efficient-sam/efficient-sam.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@
"import requests\n",
"\n",
"r = requests.get(\n",
" url='https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py',\n",
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
")\n",
"\n",
"open('notebook_utils.py', 'w').write(r.text)\n",
"open(\"notebook_utils.py\", \"w\").write(r.text)\n",
"\n",
"from notebook_utils import download_file, device_widget"
"from notebook_utils import download_file, device_widget, quantization_widget # noqa: F401"
]
},
{
Expand Down Expand Up @@ -622,11 +622,7 @@
}
],
"source": [
"to_quantize = widgets.Checkbox(\n",
" value=True,\n",
" description=\"Quantization\",\n",
" disabled=False,\n",
")\n",
"to_quantize = quantization_widget()\n",
"\n",
"to_quantize"
]
Expand Down
1 change: 0 additions & 1 deletion notebooks/hello-detection/hello-detection.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@
}
],
"source": [
"\n",
"device = device_widget()\n",
"device"
]
Expand Down
1 change: 0 additions & 1 deletion notebooks/llm-rag-langchain/llm-rag-langchain.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@
"outputs": [],
"source": [
"from pathlib import Path\n",
"import openvino as ov\n",
"import torch\n",
"import ipywidgets as widgets\n",
"from transformers import (\n",
Expand Down
1 change: 0 additions & 1 deletion notebooks/llm-rag-llamaindex/llm-rag-llamaindex.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@
"outputs": [],
"source": [
"from pathlib import Path\n",
"import openvino as ov\n",
"import ipywidgets as widgets"
]
},
Expand Down
2 changes: 0 additions & 2 deletions notebooks/object-detection-webcam/object-detection.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,6 @@
"metadata": {},
"outputs": [],
"source": [
"import ipywidgets as widgets\n",
"\n",
"core = ov.Core()\n",
"\n",
"device = utils.device_widget()\n",
Expand Down
1 change: 1 addition & 0 deletions notebooks/paint-by-example/paint-by-example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,7 @@
"\n",
"core = ov.Core()\n",
"\n",
"\n",
"def get_ov_pipeline():\n",
" image_encoder_inpaint = core.compile_model(IMAGE_ENCODER_OV_PATH_INPAINT, device.value)\n",
" unet_model_inpaint = core.compile_model(UNET_OV_PATH_INPAINT, device.value)\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -658,8 +658,6 @@
"metadata": {},
"outputs": [],
"source": [
"\n",
"\n",
"# Initialize OpenVINO runtime\n",
"core = ov.Core()\n",
"device = device_widget()\n",
Expand Down
9 changes: 1 addition & 8 deletions notebooks/pytorch-to-openvino/pytorch-onnx-to-openvino.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,7 @@
"\n",
"open(\"notebook_utils.py\", \"w\").write(r.text)\n",
"\n",
"from notebook_utils import (\n",
" segmentation_map_to_image,\n",
" viz_result_image,\n",
" SegmentationMap,\n",
" Label,\n",
" download_file,\n",
" device_widget\n",
")"
"from notebook_utils import segmentation_map_to_image, viz_result_image, SegmentationMap, Label, download_file, device_widget"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
}
],
"source": [
"device = device_widget()\n",
"device = utils.device_widget()\n",
"\n",
"device"
]
Expand Down
1 change: 1 addition & 0 deletions notebooks/yolov10-optimization/yolov10-optimization.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@
"outputs": [],
"source": [
"import openvino as ov\n",
"\n",
"core = ov.Core()\n",
"\n",
"ov_model = core.read_model(ov_model_path)\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,6 @@
}
],
"source": [
"\n",
"\n",
"device = device_widget()\n",
"\n",
"device"
Expand Down
40 changes: 16 additions & 24 deletions notebooks/yolov8-optimization/yolov8-object-detection.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
"\n",
"open(\"notebook_utils.py\", \"w\").write(r.text)\n",
"\n",
"from notebook_utils import download_file, VideoPlayer"
"from notebook_utils import download_file, VideoPlayer, device_widget, quantization_widget"
]
},
{
Expand Down Expand Up @@ -330,17 +330,7 @@
}
],
"source": [
"import ipywidgets as widgets\n",
"import openvino as ov\n",
"\n",
"core = ov.Core()\n",
"\n",
"device = widgets.Dropdown(\n",
" options=core.available_devices + [\"AUTO\"],\n",
" value=\"AUTO\",\n",
" description=\"Device:\",\n",
" disabled=False,\n",
")\n",
"device = device_widget()\n",
"\n",
"device"
]
Expand Down Expand Up @@ -387,6 +377,7 @@
],
"source": [
"import torch\n",
"import openvino as ov\n",
"\n",
"core = ov.Core()\n",
"\n",
Expand Down Expand Up @@ -785,15 +776,10 @@
}
],
"source": [
"import ipywidgets as widgets\n",
"\n",
"int8_model_det_path = models_dir / f\"{DET_MODEL_NAME}_openvino_int8_model/{DET_MODEL_NAME}.xml\"\n",
"quantized_det_model = None\n",
"\n",
"to_quantize = widgets.Checkbox(\n",
" value=True,\n",
" description=\"Quantization\",\n",
" disabled=False,\n",
")\n",
"to_quantize = quantization_widget()\n",
"\n",
"to_quantize"
]
Expand Down Expand Up @@ -1395,7 +1381,7 @@
"source": [
"from openvino.preprocess import PrePostProcessor\n",
"\n",
"ppp = PrePostProcessor(quantized_det_model)"
"ppp = PrePostProcessor(quantized_det_model if quantized_det_model is not None else det_model)"
]
},
{
Expand Down Expand Up @@ -1495,10 +1481,13 @@
"outputs": [],
"source": [
"quantized_model_with_preprocess = ppp.build()\n",
"ov.save_model(\n",
" quantized_model_with_preprocess,\n",
" str(int8_model_det_path.with_name(f\"{DET_MODEL_NAME}_with_preprocess.xml\")),\n",
")"
"\n",
"with_preprocess_path = (\n",
" int8_model_det_path.with_name(f\"{DET_MODEL_NAME}_with_preprocess.xml\")\n",
" if quantized_det_model is not None\n",
" else det_model_path.with_name(f\"{DET_MODEL_NAME}_with_preprocess.xml\")\n",
")\n",
"ov.save_model(quantized_model_with_preprocess, str(with_preprocess_path))"
]
},
{
Expand All @@ -1521,6 +1510,7 @@
"import cv2\n",
"import numpy as np\n",
"from ultralytics.utils.plotting import colors\n",
"import random\n",
"\n",
"\n",
"def plot_one_box(\n",
Expand Down Expand Up @@ -1792,6 +1782,8 @@
"import time\n",
"from IPython import display\n",
"\n",
"det_ov_model\n",
"\n",
"\n",
"# Main processing function to run object detection.\n",
"def run_object_detection(\n",
Expand Down

0 comments on commit 4fc3e73

Please sign in to comment.