Skip to content

Try to import MO as Python package#2190

Closed
dkurt wants to merge 5 commits intoopenvinotoolkit:developfrom
dkurt:mo_from_pip
Closed

Try to import MO as Python package#2190
dkurt wants to merge 5 commits intoopenvinotoolkit:developfrom
dkurt:mo_from_pip

Conversation

@dkurt
Copy link
Copy Markdown
Contributor

@dkurt dkurt commented Mar 10, 2021

Example MO install:

pip install git+https://github.com/openvinotoolkit/openvino.git#subdirectory=model-optimizer

@dkurt dkurt requested a review from mryzhov March 10, 2021 14:43
@dkurt dkurt requested a review from IRDonch March 12, 2021 06:17
@dkurt
Copy link
Copy Markdown
Contributor Author

dkurt commented Mar 12, 2021

@IRDonch, may we ask to review? This is done for MO installed by pip (as a part of openvino-dev, in example)

Copy link
Copy Markdown

@IRDonch IRDonch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to update the README with information about the updated MO search logic.

@dkurt dkurt added the downloader All about model downloading and converting tools label Mar 15, 2021
# For OpenVINO from PyPI
mo_path = subprocess.run([args.python, '-c',
'import mo,sys; sys.stdout.write(mo.__file__)'],
check=True, stdout=subprocess.PIPE).stdout.decode('utf-8')
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To decode as UTF-8, you should make sure that the process outputs UTF-8 (which you can do by adding env={**os.environ, 'PYTHONIOENCODING': 'utf-8'}).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enabled encoding='utf-8' flag

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's good, but that doesn't do the same thing. You still need to make Python output UTF-8, and you can only do that with PYTHONIOENCODING.

The script will attempt to locate Model Optimizer using the environment
variables set by the OpenVINO™ toolkit's `setupvars.sh`/`setupvars.bat`
script. You can override this heuristic with the `--mo` option:
script. Or trying to use PyPI distribution.
Copy link
Copy Markdown

@IRDonch IRDonch Mar 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or trying to use PyPI distribution.

That is not a complete sentence. It should be combined with the preceding one.

But besides that, it also needs reworking. First, it doesn't actually fit the previous sentence. If you combine them, you get "The script will attempt to locate Model Optimizer trying to use PyPI distribution", where both "attempt" and "trying" communicate the same meaning.

And second, it doesn't explain much. What PyPI distribution are you talking about? How is it used to locate Model Optimizer? I would argue that PyPI itself is actually rather irrelevant here.

Copy link
Copy Markdown
Contributor Author

@dkurt dkurt Mar 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed PyPI mention completely. With openvinotoolkit/openvino#4801 both PyPI and and just export PYTHONPATH=/path/to/openvino/model-optimizer/:$PYTHONPATH may work

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a lot better, but I think you should still explicitly say that it will try to locate MO by searching for the mo package in the Python environment.

@dkurt dkurt marked this pull request as draft March 16, 2021 07:31
@dkurt dkurt marked this pull request as ready for review March 16, 2021 08:30
@dkurt dkurt changed the title Try to import MO as a pip package Try to import MO as Python package Mar 16, 2021
mo_path = subprocess.run([args.python, '-c',
'import mo,sys; sys.stdout.write(mo.__file__)'],
check=True, stdout=subprocess.PIPE, encoding='utf-8').stdout
mo_path = (Path(mo_path).parent / '__main__.py').resolve(strict=True)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not going to work correctly, because some MO arguments used for converting models refer to files inside the MO directory, and in order for them to be located correctly, mo_path must point to the mo.py script.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basic conversion worked for me. Do you know which arguments may be affected?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any model that uses $mo_dir.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dkurt There are another issue with mo installation via proposed command. not all extensions are installed. For example extensions/front/tf/ssd_v2_support.json

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue with extensions installation has been addressed in openvinotoolkit/openvino#5302
@dkurt can you please finalize changes required to make converter work after installation of openvino-dev python package with model optimizer inside?

@dkurt dkurt marked this pull request as draft March 30, 2021 12:57
@IRDonch
Copy link
Copy Markdown

IRDonch commented May 17, 2021

Obsoleted by #2395; closing.

@IRDonch IRDonch closed this May 17, 2021
@dkurt dkurt deleted the mo_from_pip branch May 18, 2021 06:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

downloader All about model downloading and converting tools

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants