|
88 | 88 | 'lod_reset',
|
89 | 89 | 'lrn',
|
90 | 90 | 'pad',
|
| 91 | + 'pad_constant_like', |
91 | 92 | 'label_smooth',
|
92 | 93 | 'roi_pool',
|
93 | 94 | 'dice_loss',
|
@@ -4755,6 +4756,86 @@ def pad(x, paddings, pad_value=0., name=None):
|
4755 | 4756 | return out
|
4756 | 4757 |
|
4757 | 4758 |
|
| 4759 | +def pad_constant_like(x, y, pad_value=0., name=None): |
| 4760 | + """ |
| 4761 | + Pad input(Y) with :attr:`pad_value`, the number of values padded to |
| 4762 | + the edges of each axis is specified by the difference of the shape |
| 4763 | + of X and Y. ((0, shape_x_0 - shape_y_0), ... (0, shape_x_n - shape_y_n)) |
| 4764 | + unique pad widths for each axis. The input should be a k-D |
| 4765 | + tensor(k > 0 and k < 7). |
| 4766 | +
|
| 4767 | + See below for an example. |
| 4768 | +
|
| 4769 | + .. code-block:: text |
| 4770 | +
|
| 4771 | + Given: |
| 4772 | + X = [[[[ 0, 1, 2], |
| 4773 | + [ 3, 4, 5]], |
| 4774 | + [[ 6, 7, 8], |
| 4775 | + [ 9, 10, 11]], |
| 4776 | + [[12, 13, 14], |
| 4777 | + [15, 16, 17]]], |
| 4778 | + [[[18, 19, 20], |
| 4779 | + [21, 22, 23]], |
| 4780 | + [[24, 25, 26], |
| 4781 | + [27, 28, 29]], |
| 4782 | + [[30, 31, 32], |
| 4783 | + [33, 34, 35]]]] |
| 4784 | + X.shape = (2, 3, 2, 3) |
| 4785 | +
|
| 4786 | + Y = [[[[35, 36, 37]], |
| 4787 | + [[38, 39, 40]], |
| 4788 | + [[41, 42, 43]]]] |
| 4789 | + Y.shape = (1, 3, 1, 3) |
| 4790 | +
|
| 4791 | + And |
| 4792 | + pad_value = -1, |
| 4793 | +
|
| 4794 | + Return: |
| 4795 | + Out = [[[[35, 36, 37], |
| 4796 | + [-1, -1, -1]], |
| 4797 | + [[38, 39, 40], |
| 4798 | + [-1, -1, -1]], |
| 4799 | + [[41, 42, 43], |
| 4800 | + [-1, -1, -1]]], |
| 4801 | + [[[-1, -1, -1], |
| 4802 | + [-1, -1, -1]], |
| 4803 | + [[-1, -1, -1], |
| 4804 | + [-1, -1, -1]], |
| 4805 | + [[-1, -1, -1], |
| 4806 | + [-1, -1, -1]]]] |
| 4807 | + Out.shape = (2, 3, 2, 3) |
| 4808 | +
|
| 4809 | + Args: |
| 4810 | + x (Variable): The input tensor variable. |
| 4811 | + y (Variable): The input tensor variable. |
| 4812 | + pad_value (float): The constant value used to pad. |
| 4813 | + name(str|None): A name for this layer(optional). If set None, the layer |
| 4814 | + will be named automatically. |
| 4815 | +
|
| 4816 | + Returns: |
| 4817 | + Variable: The padded tensor variable. |
| 4818 | +
|
| 4819 | + Examples: |
| 4820 | + .. code-block:: python |
| 4821 | +
|
| 4822 | + # x is a rank 4 tensor variable, x.shape = (2, 3, 2, 3) |
| 4823 | + # y is a rank 4 tensor variable, y.shape = (1, 3, 1, 3) |
| 4824 | + out = fluid.layers.pad_constant_like(x=x, y=y, pad_value=0.) |
| 4825 | + # out is a rank 4 tensor variable, and out.shape = [2, 3 ,2 , 3] |
| 4826 | + """ |
| 4827 | + helper = LayerHelper('pad_constant_like', input=x, **locals()) |
| 4828 | + dtype = helper.input_dtype() |
| 4829 | + out = helper.create_tmp_variable(dtype) |
| 4830 | + helper.append_op( |
| 4831 | + type='pad_constant_like', |
| 4832 | + inputs={'X': x, |
| 4833 | + 'Y': y}, |
| 4834 | + outputs={'Out': out}, |
| 4835 | + attrs={'pad_value': float(pad_value)}) |
| 4836 | + return out |
| 4837 | + |
| 4838 | + |
4758 | 4839 | def label_smooth(label,
|
4759 | 4840 | prior_dist=None,
|
4760 | 4841 | epsilon=0.1,
|
@@ -5351,7 +5432,7 @@ def crop(x, shape=None, offsets=None, name=None):
|
5351 | 5432 | helper = LayerHelper('crop', **locals())
|
5352 | 5433 |
|
5353 | 5434 | if not (isinstance(shape, list) or isinstance(shape, tuple) or \
|
5354 |
| - isinstance(shape, Variable)): |
| 5435 | + isinstance(shape, Variable)): |
5355 | 5436 | raise ValueError("The shape should be a list, tuple or Variable.")
|
5356 | 5437 |
|
5357 | 5438 | if offsets is None:
|
|
0 commit comments