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

[Py OV] Extend Model to utilize with-expressions #27191

Merged
merged 35 commits into from
Dec 20, 2024

Conversation

almilosz
Copy link
Contributor

@almilosz almilosz commented Oct 22, 2024

Details:

  • Implement __enter__ and __exit__ to create class-based context manager
  • Remove inheritance from ModelBase in ie_api.Model and make it an attribute.
  • add private property __model that stores _pyopenvino.Model. In _pyopenvino such attribute can be accessed as _Model__model because of name mangling
  • update pyAPI methods that have std::shared_ptr<ov::Model> in their signatures.
  • add test_model_with_statement and test_model_tempdir_fails

Motivation:

On Windows reading ov.Model from temporary directory leads to PermissionError:

mem_model = generate_model_with_memory(input_shape=Shape([2, 1]), data_type=Type.f32)
with tempfile.TemporaryDirectory() as model_save_dir:
   save_model(mem_model, f"{model_save_dir}/model.xml")
   model = Core().read_model(f"{model_save_dir}/model.xml")

Tickets:

@github-actions github-actions bot added the category: Python API OpenVINO Python bindings label Oct 22, 2024
Copy link
Contributor

This PR will be closed in a week because of 2 weeks of no activity.

@github-actions github-actions bot added the Stale label Nov 24, 2024
@almilosz almilosz removed the Stale label Nov 25, 2024
@github-actions github-actions bot added the category: build OpenVINO cmake script / infra label Nov 27, 2024
@almilosz almilosz marked this pull request as ready for review November 28, 2024 13:40
@almilosz almilosz requested a review from a team as a code owner November 28, 2024 13:40
Signed-off-by: Alicja Miloszewska <[email protected]>
The test will check for both PermissionError and NoADirectoryError without python version distiction

Signed-off-by: Alicja Miloszewska <[email protected]>
Signed-off-by: Alicja Miloszewska <[email protected]>
…into almilosz/model-context

Signed-off-by: Alicja Miloszewska <[email protected]>
…into almilosz/model-context

Signed-off-by: Alicja Miloszewska <[email protected]>
Signed-off-by: Alicja Miloszewska <[email protected]>
@mlukasze mlukasze enabled auto-merge December 20, 2024 06:02
@mlukasze mlukasze added this pull request to the merge queue Dec 20, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Dec 20, 2024
@mlukasze mlukasze added this pull request to the merge queue Dec 20, 2024
Merged via the queue into openvinotoolkit:master with commit ff8146e Dec 20, 2024
188 checks passed
11happy pushed a commit to 11happy/openvino that referenced this pull request Dec 23, 2024
### Details:
- Implement `__enter__` and `__exit__` to create class-based context
manager
- Remove inheritance from ModelBase in ie_api.Model and make it an
attribute.
- add private property __model that stores `_pyopenvino.Model`. In
`_pyopenvino` such attribute can be accessed as `_Model__model` because
of name mangling
- update pyAPI methods that have `std::shared_ptr<ov::Model>` in their
signatures.
 - add `test_model_with_statement` and `test_model_tempdir_fails`
 
 ### Motivation:
On Windows reading `ov.Model` from temporary directory leads to
`PermissionError`:
 ```python
mem_model = generate_model_with_memory(input_shape=Shape([2, 1]),
data_type=Type.f32)
 with tempfile.TemporaryDirectory() as model_save_dir:
    save_model(mem_model, f"{model_save_dir}/model.xml")
    model = Core().read_model(f"{model_save_dir}/model.xml")
 ```

### Tickets:
 - CVS-106987

---------

Signed-off-by: Alicja Miloszewska <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: build OpenVINO cmake script / infra category: Python API OpenVINO Python bindings
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants