-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[Nano] add __call__ method for OpenVINOModel #5540
Merged
TheaperDeng
merged 10 commits into
intel-analytics:main
from
hjzin:openvinomodel-call-method
Sep 8, 2022
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9ef7a58
[Nano] support __call__ method for OpenVINOModel
hjzin c45dc49
remove unnecessary kwargs in __call__ method of OpenVINOModel
hjzin 9ec7afe
specify which __call__ method to call in KerasOpenVINOModel
hjzin 66737f0
remove whitespace
hjzin d29cf9a
make KerasOpenVINOModel and PytorchOpenVINOModel not inherit from Ope…
hjzin 2608a4a
fix docstring of OpenVINOModel._save_model
hjzin 7adb546
remove extra import
hjzin 33da942
fix _save_model
hjzin 3d84ffb
change_save_model
hjzin 1d085e3
simplify _model_exists_or_error
hjzin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -30,6 +30,9 @@ def __init__(self, ie_network: str, device='CPU'): | |||||||
def forward_step(self, *inputs): | ||||||||
return self._infer_request.infer(list(inputs)) | ||||||||
|
||||||||
def __call__(self, *inputs): | ||||||||
return self.forward_step(*inputs) | ||||||||
|
||||||||
@property | ||||||||
def forward_args(self): | ||||||||
return self._forward_args | ||||||||
|
@@ -50,18 +53,17 @@ def ie_network(self, model): | |||||||
input_names = [t.any_name for t in self._ie_network.inputs] | ||||||||
self._forward_args = input_names | ||||||||
|
||||||||
def _save_model(self, path): | ||||||||
def _save(self, path): | ||||||||
""" | ||||||||
Save PytorchOpenVINOModel to local as xml and bin file | ||||||||
Save OpenVINOModel to local as xml and bin file | ||||||||
|
||||||||
:param path: Directory to save the model. | ||||||||
""" | ||||||||
path = Path(path) | ||||||||
path.mkdir(exist_ok=True) | ||||||||
invalidInputError(self.ie_network, | ||||||||
"self.ie_network shouldn't be None.") | ||||||||
xml_path = path / self.status['xml_path'] | ||||||||
save(self.ie_network, xml_path) | ||||||||
if self._model_exists_or_err("self.ie_network shouldn't be None."): | ||||||||
path = Path(path) | ||||||||
path.mkdir(exist_ok=True) | ||||||||
xml_path = path / 'ov_saved_model.xml' | ||||||||
save(self.ie_network, xml_path) | ||||||||
|
||||||||
def pot(self, | ||||||||
dataloader, | ||||||||
|
@@ -148,3 +150,8 @@ def pot(self, | |||||||
model = Core().read_model(model_path) | ||||||||
model.reshape(orig_shape) | ||||||||
return model | ||||||||
|
||||||||
def _model_exists_or_err(self, err_msg): | ||||||||
if self.ie_network is None: | ||||||||
invalidInputError(False, err_msg) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
remove if.