def propagate_pad(op): # type: (ONNXOperation)->typing.Tuple[typing.List[typing.List[int]], typing.List[str]] if 'paddings' in op.attribs: paddings = op.attribs['paddings'] elif 'pads' in op.attribs: paddings = op.attribs['pads'] else: assert False return [ infer.pad(input=op.input.shape, padding=to_nnef_padding(paddings)) ], [op.input.dtype]
def pad_image_shape(op): # type: (Caffe2Operation)->ShapeResult is_nhwc = op.attribs.get('order', 'NCHW').upper() == 'NHWC' def expand(list, default): if is_nhwc: return [default] + list + [default] else: return [default, default] + list return infer.pad(input=op.inputs[0].shape, padding=expand( caffe2_pads_to_nnef_padding(op.attribs['pads']), (0, 0))), op.inputs[0].dtype
def propagate_pad(op, const_value_by_tensor): # type: (TFOperation, _ConstValueByTensorT)->typing.Tuple[typing.List[typing.List[int]], typing.List[str]] input, paddings = op.inputs paddings = const_value_by_tensor[paddings].tolist() # type: typing.List[typing.Tuple[int, int]] return [infer.pad(input=input.shape, padding=paddings)], [op.attribs['T']]
def test_pad(self): self.assertEqual([2, 7, 12], infer.pad([1, 2, 3], [(0, 1), (2, 3), (4, 5)]))