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

Reshape able slice #1241

Merged
merged 22 commits into from
Aug 10, 2020
Merged

Conversation

pavel-esir
Copy link
Contributor

@pavel-esir pavel-esir commented Jul 7, 2020

Description:

  • freshened Slice extractor for Caffe, now it's CaffeSlice
  • added AttributedSlice for ONNX opset < 10 models
  • added TFSlice internal operation for Slice operation in TF; needed because semantic is different that in ONNX
  • removed attributes of internal Slice operation: now it's has exact semantic as ONNX Slice opset >= 10
  • corrected SliceConverter to support reshape-able Slic, no need for multiple nested ifs

Cherry-pick form here #1194
- removed Slice operation in Kaldi
- parallel component in Kaldi is supported by Split operation
previous paragraph is not actual anymore, mentioned PR was merged

#34041

Code:

  • Comments
  • Code style (PEP8)
  • Transformation generates reshape-able IR
  • Transformation preserves original framework node names

Validation:

  • Unit tests:
  • Framework operation tests
  • Transformation tests
  • e2e model test with an update of ./tests/e2e_oss/utils/reshape_utils.py: N/A -- no new models added to e2e tests
  • Model Optimizer IR Reader check

Documentation:

  • Supported frameworks operations list: N/A
  • Supported public models list: N/A
  • New operations specification: N/A
  • Guide on how to convert the public model: N/A
  • User guide update: N/A

@pavel-esir pavel-esir force-pushed the reshape-able-slice branch from 61937ba to e43d33b Compare July 7, 2020 16:07
@pavel-esir pavel-esir marked this pull request as ready for review July 7, 2020 16:09
@pavel-esir pavel-esir requested review from a team and vgavrilo July 7, 2020 16:09
@ilya-lavrenov ilya-lavrenov added the category: MO Model Optimizer label Jul 8, 2020
@ilya-lavrenov ilya-lavrenov added this to the 2021.1 milestone Jul 8, 2020
model-optimizer/extensions/front/caffe/slice_ext.py Outdated Show resolved Hide resolved
model-optimizer/extensions/front/onnx/slice_ext.py Outdated Show resolved Hide resolved
model-optimizer/extensions/front/onnx/slice_ext.py Outdated Show resolved Hide resolved
model-optimizer/extensions/front/tf/slice_ext.py Outdated Show resolved Hide resolved
model-optimizer/extensions/front/tf/slice_replacers.py Outdated Show resolved Hide resolved
model-optimizer/extensions/front/tf/slice_replacers.py Outdated Show resolved Hide resolved
model-optimizer/extensions/front/tf/slice_replacers.py Outdated Show resolved Hide resolved
model-optimizer/extensions/front/tf/slice_replacers.py Outdated Show resolved Hide resolved
model-optimizer/mo/ops/slice.py Show resolved Hide resolved
@pavel-esir pavel-esir force-pushed the reshape-able-slice branch 6 times, most recently from 26b3843 to a76ebcf Compare July 20, 2020 11:11
@pavel-esir pavel-esir force-pushed the reshape-able-slice branch from a76ebcf to 322142e Compare July 23, 2020 11:36
@pavel-esir pavel-esir force-pushed the reshape-able-slice branch from 322142e to 4dfa2f3 Compare July 23, 2020 13:53
model-optimizer/mo/utils/unittest/graph.py Outdated Show resolved Hide resolved
model-optimizer/extensions/front/caffe/slice_ext.py Outdated Show resolved Hide resolved
model-optimizer/mo/ops/slice.py Outdated Show resolved Hide resolved
model-optimizer/mo/utils/unittest/graph.py Outdated Show resolved Hide resolved
model-optimizer/mo/utils/shape.py Outdated Show resolved Hide resolved
model-optimizer/mo/utils/shape.py Outdated Show resolved Hide resolved
model-optimizer/mo/utils/shape.py Outdated Show resolved Hide resolved
model-optimizer/mo/ops/slice.py Outdated Show resolved Hide resolved
model-optimizer/mo/ops/slice_test.py Outdated Show resolved Hide resolved
@pavel-esir pavel-esir force-pushed the reshape-able-slice branch 2 times, most recently from 55eadc5 to 0fd6d56 Compare August 2, 2020 17:14
@lazarevevgeny
Copy link
Contributor

@jane-intel , please, review the PR.

model-optimizer/mo/ops/slice.py Outdated Show resolved Hide resolved
model-optimizer/mo/utils/shape.py Outdated Show resolved Hide resolved
model-optimizer/mo/utils/unittest/graph.py Outdated Show resolved Hide resolved
@lazarevevgeny
Copy link
Contributor

@jane-intel, please, take a look.

…corrected SliceConverter and added unittests for all cases
…ence; moved mxlice inside of slice.py; renamed slice_replacers
Copy link
Contributor

@lazarevevgeny lazarevevgeny left a comment

Choose a reason for hiding this comment

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

LGTM. @jane-intel, please, have a fresh look at this PR.


def replace_sub_graph(self, graph: Graph, match: dict):
"""
This transformation converts TFSlice to internal Slice operation.
Copy link
Contributor

Choose a reason for hiding this comment

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

Transformation itself is not commented -- what is happening

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved comments to class level. Please review.


"""
Slicing operations have different semantic or different parameters/inputs in different frameworks. To distinguish them
and not confuse with OpenVINO Slice several Model Optimizer internal operations are introduced. OpenVINO Slice operation
Copy link
Contributor

Choose a reason for hiding this comment

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

there is no OpenVINO Slice operation. We should not confuse people

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree. Clarified this. Please review.



class Slice(Op):
"""
Semantic of OpenVINO Slice operation is identical ONNX Slice (opset >= 10).
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no OpenVINO Slice operation. It is not in public opset

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated comments. Please review.


def __init__(self, graph: Graph, attrs: dict):
def __init__(self, graph: Graph, attrs: dict = None):
Copy link
Contributor

Choose a reason for hiding this comment

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

Here you set arrts to None, but everywhere else -- we don't do this. What was original reason to do so?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added this default value to avoid specifying when I call constrictor, e.g. here TFSliceToSlice.py:41
slice_node = Slice(graph).create_node()

At the moment it looks like it's the only place where Slice constructor is called explicitly. I guess in the draft versions of PR i was using it more often and it remained here for historical reason. I advocate to leave this default argument here.

model-optimizer/mo/ops/slice.py Outdated Show resolved Hide resolved
@pavel-esir pavel-esir requested a review from jane-intel August 7, 2020 12:59
@lazarevevgeny lazarevevgeny merged commit 75d2d88 into openvinotoolkit:master Aug 10, 2020
mryzhov pushed a commit to mryzhov/openvino that referenced this pull request Aug 26, 2020
* Added Caffe Slice_ext

* Added TFSlice, AttributedSlice (both with extractors and replacers), corrected SliceConverter and added unittests for all cases

* added comments to each type of Slice operation; optimized shape inference; moved mxlice inside of slice.py; renamed slice_replacers

* removed type annotation for get_shape_after_slice routine

* replaced zeros_like with zeros

* Corrected preserving node names, renamed attributes names, added tests fro slice_replacer onnx phase

* Renamed slice_replacers.py

* added more unittest cases

* added type annotations, moved to more relevant place routines for shape calculation, and some other minor corrections

* corrected a typo `normalize_slice_indices` comment

* corrected shape calculation for Nonconstant inputs

* corrected a few typos

* corrected type declarations

* corrected shape inference with rounding

* refactored unit-tests for front transforms of Slice

* added error raising for negative and zero shapes

* removed magic_num

* corrected AttributedSlice, clarified comments

* fixed unit-test for AttributedSliceToSlice

* typo in type hints corrected

* removed supported_attrs

* returned back default None for attrs of Slice
RomanZm pushed a commit to RomanZm/openvino that referenced this pull request Aug 28, 2020
* Added Caffe Slice_ext

* Added TFSlice, AttributedSlice (both with extractors and replacers), corrected SliceConverter and added unittests for all cases

* added comments to each type of Slice operation; optimized shape inference; moved mxlice inside of slice.py; renamed slice_replacers

* removed type annotation for get_shape_after_slice routine

* replaced zeros_like with zeros

* Corrected preserving node names, renamed attributes names, added tests fro slice_replacer onnx phase

* Renamed slice_replacers.py

* added more unittest cases

* added type annotations, moved to more relevant place routines for shape calculation, and some other minor corrections

* corrected a typo `normalize_slice_indices` comment

* corrected shape calculation for Nonconstant inputs

* corrected a few typos

* corrected type declarations

* corrected shape inference with rounding

* refactored unit-tests for front transforms of Slice

* added error raising for negative and zero shapes

* removed magic_num

* corrected AttributedSlice, clarified comments

* fixed unit-test for AttributedSliceToSlice

* typo in type hints corrected

* removed supported_attrs

* returned back default None for attrs of Slice
@pavel-esir pavel-esir deleted the reshape-able-slice branch September 18, 2020 08:57
@pavel-esir pavel-esir added bug Something isn't working and removed bug Something isn't working labels May 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: MO Model Optimizer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants