New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Object Detection Demo Jupyter Notebook #2093
Object Detection Demo Jupyter Notebook #2093
Conversation
Can one of the admins verify this patch? |
@helena-intel that basically work for me (tested on Windows). Although get some questions:
|
Jenkins please retry a build |
If you change the base_model_dir and omz_cache_dir in the Settings cell (at the top) it will not redownload everything and just use the models that are there. But as far as I know there is no way to set this from the command line when you start Jupyter. I plan to reuse this directory across all demo's (and am happy to change to other directory names) so then a user only needs to download once. I already made a subset of models to download by default. I can make that a lot smaller. I can also highlight the setting in the README and make it a highlighted alert box in the notebook itself.
Correct. The instructions were for people who are completely new to this and do not have OpenVINO installed yet. I will update the instructions, also to account for the new pip method. I can add an "if you have already installed OpenVINO" part to the instructions (where I can also point to the directory settings). I would like to still keep this method to install everything including openvino with |
@helena-intel please note pre-commit style check failed: |
Jenkins please retry a build |
Apologies, I fixed that, and found the |
Jenkins please retry a build |
1 similar comment
Jenkins please retry a build |
I added a NotebookDemo to the demo tests and a test case for this object detection notebook. The test converts the notebook to a Python script and runs it with default arguments. For now, the test case only tests that the notebook runs without exceptions (so it catches import errors etc.) not if there is actually useful output. I will update the test to a more useful one if this is the right approach. |
Jenkins please retry a build |
Jenkins please retry a build |
@helena-intel we need to update CI requirements in order to make this work. |
This makes the subprocess call to model downloader work in virtual environments
…in CI Co-authored-by: Vladimir Dudnik <vladimir.dudnik@intel.com>
c9793fb
to
0a28004
Compare
Jenkins please retry a build |
@nignatovsky please check your modification of requirements for CI. On Linux it gives an error: |
demos/object_detection_demo/jupyter-python/object_detection_demo.ipynb
Outdated
Show resolved
Hide resolved
demos/object_detection_demo/jupyter-python/object_detection_demo.ipynb
Outdated
Show resolved
Hide resolved
Jenkins please retry a build |
Fix to make jupyter work in CI Co-authored-by: Nikita Ignatovsky <73649020+nignatovsky@users.noreply.github.com>
Jenkins please retry a build |
demos/tests/cases.py
Outdated
# Change the working directory to the directory that contains the notebook | ||
changedir = f"import os\nos.chdir(r'{os.path.dirname(python_file)}')\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed? The script ought to work from any directory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the notebook is run, the current directory is the notebook directory, and imports from that directory work. This makes the test script do the same thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the notebook is run, the current directory is the notebook directory
Not necessarily, the user could run it from any directory.
and imports from that directory work
Is it really required for the current directory to be the notebook directory for the imports to work?
…ning, updated installation instructions, updated error message in notebook
@IRDonch thanks for your review and suggestions! I have implemented most of your suggestions now, and marked those conversations as resolved. |
Jenkins please retry a build |
@helena-intel please take a look at pre-commit failures: 12:55:42 Fixed arguments: /home/jenkins/workspace/omz/precommit/demos_ubuntu18/venv/bin/python /home/jenkins/workspace/omz/precommit/demos_ubuntu18/src/demos/object_detection_demo/jupyter_python/object_detection_demo_test.py |
@vladimir-dudnik After reading the change requests, and changing the command to run jupyter, I had hoped that the PATH and PYTHONPATH variables were unnecessary now, so I removed them. The test did pass on my local machine. I'll add the PATH variable back. That should hopefully fix this. Is there a way for me to check the CI pipeline without making a commit and update the PR? |
…alled by openvino-dev)
Jenkins please retry a build |
@helena-intel without making commit you can only test this locally, by making the same environment and call run_tests.py |
Jenkins please retry a build |
2 similar comments
Jenkins please retry a build |
Jenkins please retry a build |
@helena-intel still can't find script file 17:00:20 /home/jenkins/workspace/omz/precommit/demos_ubuntu18/venv/bin/python: can't open file '/home/jenkins/workspace/omz/precommit/demos_ubuntu18/src/demos/object_detection_demo/jupyter_python/object_detection_demo_test.py': [Errno 2] No such file or directory |
@vladimir-dudnik I think the recent commit doesn't fix it. Working on it now. |
demos/tests/cases.py
Outdated
# Change the working directory to the directory that contains the notebook | ||
changedir = f"import os\nos.chdir(r'{os.path.dirname(python_file)}')\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the notebook is run, the current directory is the notebook directory
Not necessarily, the user could run it from any directory.
and imports from that directory work
Is it really required for the current directory to be the notebook directory for the imports to work?
demos/requirements.txt
Outdated
@@ -8,3 +8,6 @@ tokenizers | |||
tensorboard | |||
tensorboardX | |||
tqdm | |||
jupyterlab | |||
ipywidgets | |||
opencv-python-headless |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove OpenCV from here, as well. Also, keep the list in alphabetic order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You also need to regenerate ci/requirements-demos.txt
from the new version of this file.
demos/object_detection_demo/jupyter_python/object_detection_demo.ipynb
Outdated
Show resolved
Hide resolved
demos/object_detection_demo/jupyter_python/object_detection_demo.ipynb
Outdated
Show resolved
Hide resolved
demos/object_detection_demo/jupyter_python/object_detection_demo.ipynb
Outdated
Show resolved
Hide resolved
demos/object_detection_demo/jupyter_python/object_detection_demo.ipynb
Outdated
Show resolved
Hide resolved
demos/object_detection_demo/jupyter_python/object_detection_demo.ipynb
Outdated
Show resolved
Hide resolved
demos/object_detection_demo/jupyter_python/object_detection_demo.ipynb
Outdated
Show resolved
Hide resolved
# Set User-Agent to Mozilla because some websites block requests with User-Agent Python | ||
request = urllib.request.Request(path, headers={"User-Agent": "Mozilla/5.0"}) | ||
response = urllib.request.urlopen(request) | ||
data = response.read() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems dangerous to load the whole file into memory at once. It could be multiple gigabytes in size. I would suggest to download it in chunks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm afraid the notebook will have more problems if people start using multi-gigabyte video's... (The instructions say to use small video's too). I'll change it though, it is good to err on the safe side.
Co-authored-by: Roman Donchenko <roman.donchenko@intel.com>
Wrap reading file object with `with` statement Update and sort demo requirements Use fnmatch instead of re Use pathlib for paths Select IR models based on dldt framework Delete demo_env from tests (should no longer be necessary) Reformat template for adding test code to script in cases.py/NotebookDemo Test uses FP32 models instead of FP16 Skip model downloading in test
…tel/open_model_zoo into object-detection-demo-notebook
Jenkins please retry a build |
# Add `test_code` to the test script and make it accept command line arguments | ||
content = f""" | ||
import os | ||
os.chdir(r'{os.path.dirname(python_file)}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
os.chdir(r'{os.path.dirname(python_file)}') | |
os.chdir({os.path.dirname(python_file)!r}) |
Let Python escape any special characters for you. :-)
# Change settings for test script | ||
base_model_dir=dirname(dirname(dirname(dirname(args.m)))) | ||
|
||
PRECISION = 'FP32' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like this ought to be part of the test code.
we will close this PR in favour of new repo especially created to develop and distribute OpenVINO jupyter notebook demos. |
Jupyter Notebook for Async Object Detection. I took the Python demo and made it into a notebook that allows a user to select a model and a video (or upload a video of their own), and set settings for
max_num_requests
,num_threads
andnum_streams
.The notebook downloads the model, optionally converts it, does inference, and shows the results. It shows "live" results of a selected model on one video, and on three frames of multiple selected models (to quickly compare results). By default currently only Intel models are used because they do not require using the model converter, so this notebook can be used with the pip version of OpenVINO. I can update this when the model optimizer becomes part of the pip distribution.
The target audience for this notebook includes less experienced developers. The goal of this specific notebook is to demonstrate Object Detection with the Async API. I will also make more introductionary notebooks for using OpenVINO/OMZ in general.
Try without installing
You can try it here: https://mybinder.org/v2/gh/helena-intel/open_model_zoo/object-detection-demo-notebook-binder?filepath=%2Fdemos%2Fobject_detection_demo%2Fjupyter-python%2Fobject_detection_demo.ipynb There is also a version where the code is hidden: https://mybinder.org/v2/gh/helena-intel/open_model_zoo/detection-async-notebook?urlpath=voila%2Frender%2Fobject_detection_demo.ipynb Note that performance may be slow and it may randomly crash.
README/Usage notes
The README instructions need to be updated, but I wanted to wait for the updated pip install method to do that. If you already have OpenVINO installed you can run the notebook from a terminal/cmd.exe where you have set the PATH/LD_LIBRARY_PATH or run setupvars. Then install the requirements in the demos/object_detection_demo/jupyter-python folder and run the notebook, with jupyter notebook or jupyter lab. Note: the notebook calls subprocess to run the model optimizer. If you use a virtualenv, this only works if your environment variables are set globally. If you set them in the shell before running the notebook, subprocess doesn't see them. With the new pip release this should no longer be an issue (otherwise I can change the subprocess call).
Tested on Windows and Linux (Ubuntu 18).
Notes and questions
num_threads
,num_streams
andmax_num_requests
but I don't know enough about this to write this.detection_utils
file and some directly in the notebook. I tried to find a balance, so that the important code for this demo is still in the notebook, but that it is not too much code. I am not sure if I found the right balance.$HOME/open_model_zoo_models
and set the cache to$HOME/open_model_zoo_cache
. I keep the converted models in the same directory as the downloaded models. I am happy to change these directories to something else, I do not know what is best practice. I would like to have a standard directories for this that always work, so that I can use them for further OMZ notebooks.Screenshots of the completed notebook and app-version