Skip to content
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

Replace openvino-dev with OpenVINO Runtime inference #7843

Merged

Conversation

GabrielDornelles
Copy link
Contributor

@GabrielDornelles GabrielDornelles commented May 16, 2022

One of OpenVINO use cases is to run it on Raspberry devices. I'm proposing to make the inference using openvino.runtime, which is installable at raspberry and is available at latest openvino package (tested with openvino==2022.1.0).

The previous inference using openvino-dev was not usable at devices where the dev package is not available.

🛠️ PR Summary

Made with ❤️ by Ultralytics Actions

🌟 Summary

Improved OpenVINO integration in YOLOv5's model loading and inference.

📊 Key Changes

  • Updated OpenVINO package requirement from openvino-dev to openvino.
  • Switched to newer OpenVINO Python API usage with Core instead of IECore.
  • Simplified OpenVINO network reading and compiling processes.
  • Streamlined OpenVINO inference code to reduce verbosity and complexity.

🎯 Purpose & Impact

  • Purpose: The update ensures compatibility with the latest OpenVINO version and takes advantage of the more user-friendly API.
  • Impact: Users leveraging OpenVINO for model inference will experience a more straightforward setup with potentially enhanced stability and performance improvements. 🚀

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

👋 Hello @GabrielDornelles, thank you for submitting a YOLOv5 🚀 PR! To allow your work to be integrated as seamlessly as possible, we advise you to:

  • ✅ Verify your PR is up-to-date with upstream/master. If your PR is behind upstream/master an automatic GitHub Actions merge may be attempted by writing /rebase in a new comment, or by running the following code, replacing 'feature' with the name of your local branch:
git remote add upstream https://github.com/ultralytics/yolov5.git
git fetch upstream
# git checkout feature  # <--- replace 'feature' with local branch name
git merge upstream/master
git push -u origin -f
  • ✅ Verify all Continuous Integration (CI) checks are passing.
  • ✅ Reduce changes to the absolute minimum required for your bug fix or feature addition. "It is not daily increase but daily decrease, hack away the unessential. The closer to the source, the less wastage there is." -Bruce Lee

@glenn-jocher
Copy link
Member

@GabrielDornelles thanks for the PR! Is there a way to use the openvino package for export also instead of openvino-dev?

yolov5/export.py

Lines 171 to 187 in 2b64b45

def export_openvino(model, im, file, half, prefix=colorstr('OpenVINO:')):
# YOLOv5 OpenVINO export
try:
check_requirements(('openvino-dev',)) # requires openvino-dev: https://pypi.org/project/openvino-dev/
import openvino.inference_engine as ie
LOGGER.info(f'\n{prefix} starting export with openvino {ie.__version__}...')
f = str(file).replace('.pt', f'_openvino_model{os.sep}')
cmd = f"mo --input_model {file.with_suffix('.onnx')} --output_dir {f} --data_type {'FP16' if half else 'FP32'}"
subprocess.check_output(cmd, shell=True)
LOGGER.info(f'{prefix} export success, saved as {f} ({file_size(f):.1f} MB)')
return f
except Exception as e:
LOGGER.info(f'\n{prefix} export failure: {e}')

@GabrielDornelles
Copy link
Contributor Author

@GabrielDornelles thanks for the PR! Is there a way to use the openvino package for export also instead of openvino-dev?

yolov5/export.py

Lines 171 to 187 in 2b64b45

def export_openvino(model, im, file, half, prefix=colorstr('OpenVINO:')):
# YOLOv5 OpenVINO export
try:
check_requirements(('openvino-dev',)) # requires openvino-dev: https://pypi.org/project/openvino-dev/
import openvino.inference_engine as ie
LOGGER.info(f'\n{prefix} starting export with openvino {ie.__version__}...')
f = str(file).replace('.pt', f'_openvino_model{os.sep}')
cmd = f"mo --input_model {file.with_suffix('.onnx')} --output_dir {f} --data_type {'FP16' if half else 'FP32'}"
subprocess.check_output(cmd, shell=True)
LOGGER.info(f'{prefix} export success, saved as {f} ({file_size(f):.1f} MB)')
return f
except Exception as e:
LOGGER.info(f'\n{prefix} export failure: {e}')

I believe yes, I uninstalled dev package and the command works the same way in the non-dev package. The only thing is that it doesn't have a __version__ method, but it has a get_version that will display the following:

image

@glenn-jocher
Copy link
Member

@GabrielDornelles looking at these two it seems that we still need openvino-dev for export:
https://pypi.org/project/openvino/
https://pypi.org/project/openvino-dev/

I'll take a closer look

@glenn-jocher glenn-jocher changed the title Uses OpenVINO runtime instead of openvino-dev Replace openvino-dev with OpenVINO Runtime inference May 16, 2022
@glenn-jocher glenn-jocher merged commit 05d4fc9 into ultralytics:master May 16, 2022
@glenn-jocher
Copy link
Member

@GabrielDornelles PR is merged. I validated PR and master exported OpenVINO models and saw same mAP. Also openvino-dev install provides for import openvino, so no changes needed by default for existing users.

Thank you for your contributions to YOLOv5 🚀 and Vision AI ⭐

tdhooghe pushed a commit to tdhooghe/yolov5 that referenced this pull request Jun 10, 2022
)

* Uses OpenVINO runtime instead of openvino-dev

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* export with openvino package

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Revert export.py

* Update common.py

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
ctjanuhowski pushed a commit to ctjanuhowski/yolov5 that referenced this pull request Sep 8, 2022
)

* Uses OpenVINO runtime instead of openvino-dev

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* export with openvino package

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Revert export.py

* Update common.py

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants