Files
openvino/model-optimizer/extensions/ops/GRUCell.py
T
Anton Chetverikov 6b54e738d7 Update operation attributes (#3814)
* Allign attribute values in spec

* Fix wrong attribute name in spec

* Add `get_boolean_attr` function

* Add get_type function

* Update conv attrs

* Update copyright year

* Add missed attrs, update copyright year

* Fix year in copyright

* Update ir parser for RegionYolo layer

* Remove wrong changes for BinaryConvolution

* Remove get_type function as it no more needed

* Update check for reduce ops

* Fix error in reduce attrs

* Update ir_engine to work with bool attrs

* Update DetectionOutput operation

* Update PSROIPooling

* remove redundant attrs from spec

* Update get_boolean_attr function

* Update Reduce operations

* Update DetectionOutput specification

* Update specification for missed attrs

* Apply comments

* Fixconst renumbering logic

* Fix typo

* Change default value to fix broken shape inference

* Add additional asserts

* Add comment

* model-optimizer/mo/utils/ir_reader/layer_to_class.py

* Sort imports

* Sort imports

* Update year in copyright

* Update const

* Remove changes from const restoring

* Rename function

* remove unnecessary changes

* model-optimizer/mo/front/extractor_test.py

* Fix year in copyright

* Add soft_get

* Fix exclude-pad attribute name for AvgPool operation

* Update exclude_pad attribute values

* Remove useless comment

* Update examples in specification

* Remove file added by mistake

* Resolve comments

* Resolve comments

* Add return value

* Allign global_pool attribute
2021-01-29 10:08:06 +03:00

89 lines
2.9 KiB
Python

"""
Copyright (C) 2018-2021 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
from mo.front.common.partial_infer.utils import mark_input_bins
from mo.front.extractor import bool_to_str
from mo.graph.graph import Node, Graph
from mo.ops.op import Op
from mo.utils.error import Error
class GRUCell(Op):
""" A single GRU cell (without a loop).
2 inputs:
- [0, required] input data (2D),
- [1, required] initial hidden state (2D),
2 blobs:
- [2, required] cell FC weights
- [3, required] cell FC biases
1 outputs:
- [required] output data / resulting hidden state (2D)
"""
op = 'GRUCell'
def __init__(self, graph: Graph, attrs: dict):
mandatory_props = {
'type': __class__.op,
'op': __class__.op,
'infer': __class__.infer,
'in_ports_count': 4,
'out_ports_count': 1,
'version': 'opset3',
'wr_input_id': 2,
'gates_count': 3,
'linear_before_reset': False,
}
super().__init__(graph, mandatory_props, attrs)
def supported_attrs(self):
return [
'hidden_size', # number of the elements in hidden cell size
'activations',
'activation_alpha',
'activation_beta',
'clip',
'linear_before_reset',
]
def backend_attrs(self):
return [
'hidden_size', # number of the elements in hidden cell size
('activations', lambda node: ','.join(node.activations) if node.activations is not None else None),
'activation_alpha',
'activation_beta',
'clip',
('linear_before_reset', lambda node: bool_to_str(node, 'linear_before_reset')),
]
@staticmethod
def infer(node: Node):
assert len(node.out_nodes()) in [1, 2]
hidden_shape = node.in_node(1).shape.copy()
mark_input_bins(node, start_port=2)
node.out_node(0).shape = hidden_shape
hidden_size = hidden_shape[1]
if node.has_valid('hidden_size'):
if node.hidden_size != hidden_size:
raise Error("Input shape {} for hidden size doesn't match pre-defined hidden_size in node {}".format(
node.in_node(1).shape, node.soft_get('name')))
else:
node['hidden_size'] = hidden_size