Skip to content
This repository has been archived by the owner on Dec 1, 2021. It is now read-only.

Support import of Sub operator #941

Merged
merged 4 commits into from
May 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions blueoil/converter/core/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -1570,6 +1570,61 @@ def preserve_quantization(self) -> bool:
return False


class Sub(Operator):
"""Subtract operator.

Performs element-wise subtraction (with Numpy-style broadcasting support).
This operator supports multidirectional (i.e., Numpy-style) broadcasting.

Inputs
------
A
First operand.

B
Second operand.

Outputs
-------
C
Result, has same element type as two inputs

"""

_input_names = ['A', 'B']
_output_names = ['C']

def __init__(self,
name: str,
shape: List[int],
dtype: DataType,
input_ops: Ops,
dimension_format: str = 'NHWC') -> None:
super().__init__(name, shape, dtype, input_ops, dimension_format=dimension_format)

def _check_consistency(self) -> None:
super()._check_consistency()

def run_forward(self) -> np.ndarray:
a = self._input_ops['A'].data
b = self._input_ops['B'].data
self._data = a - b
return self._data

@property
def is_monotonic(self) -> bool:
return False

@classmethod
def infer_shape(cls, lists: Dict[str, List[int]], format: str, input_formats: List[str],
attrs: Dict[str, Any]) -> List[int]:
return lists['X']

@property
def preserve_quantization(self) -> bool:
return False


class Pool(Operator):
"""Pooling operator.

Expand Down
14 changes: 13 additions & 1 deletion blueoil/converter/plugins/tf.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from blueoil.converter.core.graph import Graph
from blueoil.converter.core.operators import Operator, Conv, \
Identity, BinaryMeanScalingQuantizer, \
BatchNormalization, LinearMidTreadHalfQuantizer, Add, \
BatchNormalization, LinearMidTreadHalfQuantizer, Add, Sub, \
MaxPool, AveragePool, Reshape, Softmax, Transpose, Relu, SpaceToDepth, \
Mul, BinaryChannelWiseMeanScalingQuantizer, ConcatOnDepth, Maximum, \
DepthToSpace, ResizeNearestNeighbor, \
Expand Down Expand Up @@ -700,6 +700,18 @@ def infer_dtype() -> DataType:
input_ops,
dimension_format=current_format
)
elif op_type == 'Sub':
if not shape:
attributes = {}
shape = infer_shape(attributes)

new_op = Sub(
node.name,
shape,
dtype,
input_ops,
dimension_format=current_format
)
elif op_type == 'Identity':
if not shape:
attributes = {}
Expand Down