未验证 提交 468f8815 编写于 作者: 傅剑寒 提交者: GitHub

(fluid清理)Remove filter by instag in nn.py under fluid (#47929)

上级 27e252d9
...@@ -23,7 +23,7 @@ import numpy as np ...@@ -23,7 +23,7 @@ import numpy as np
import paddle import paddle
from ..layer_helper import LayerHelper from ..layer_helper import LayerHelper
from paddle.fluid.framework import _in_legacy_dygraph from paddle.fluid.framework import _in_legacy_dygraph
from ..initializer import Normal, Constant, NumpyArrayInitializer from ..initializer import Normal, Constant
from ..framework import ( from ..framework import (
Variable, Variable,
OpProtoHolder, OpProtoHolder,
...@@ -182,7 +182,6 @@ __all__ = [ ...@@ -182,7 +182,6 @@ __all__ = [
'sign', 'sign',
'unfold', 'unfold',
'deformable_roi_pooling', 'deformable_roi_pooling',
'filter_by_instag',
'shard_index', 'shard_index',
'hard_swish', 'hard_swish',
'mish', 'mish',
...@@ -9951,75 +9950,6 @@ def flatten(x, axis=1, name=None): ...@@ -9951,75 +9950,6 @@ def flatten(x, axis=1, name=None):
return out return out
@templatedoc(op_type="filter_by_instag")
def filter_by_instag(ins, ins_tag, filter_tag, is_lod, out_val_if_empty=0):
"""
**Filter By Instag Layer**
This function filter a batch of ins by instag,
There are multiple ins, and every ins belongs to some tags.
We can specify some tags we want. So the ins which belongs to that tags
remains in the output, and others removed.
For example, one batch has 4 ins. Every ins has its tag list.
| Ins | Ins_Tag |
|:-----:|:------:|
| 0 | 0, 1 |
| 1 | 1, 3 |
| 2 | 0, 3 |
| 3 | 2, 6 |
And Lod is [1,1,1,1]
And the filter tags [1]
From the definition above, ins which has tag 1 can pass the filter
So Ins 0 and Ins 1 can pass and be seen in the output,
Ins 2 and 3 cannot pass because they do not has tag 1.
Actually, if is_lod is false, it is normal tensor that equals to
lod_tensor with all 1, similar to the example above.
Args:
ins (Variable): Input Variable (LoDTensor), usually it is 2D tensor
And first dimension can have lod info or not.
ins_tag (Variable): Input Variable (LoDTensor), usually it is 1D list
And split them by lod info
filter_tag (Variable): Input Variable (1D Tensor/List), usually it is
list that holds the tags.
is_lod (Bool): Boolean value to indicate ins is lod tensor or not.
out_val_if_empty(Int64): If the output after filter is empty, this value
will be set to Output tensor.
Returns:
Variable: filtered ins (LoDTensor) and loss weight (Tensor)
Examples:
.. code-block:: python
import paddle.fluid.layers as layers
ins = layers.data(name='Ins', shape=[-1,32], lod_level=0, dtype='float64')
ins_tag = layers.data(name='Ins_tag', shape=[-1,16], lod_level=0, dtype='int64')
filter_tag = layers.data(name='Filter_tag', shape=[-1,16], dtype='int64')
out, loss_weight = layers.filter_by_instag(ins, ins_tag, filter_tag, True)
"""
helper = LayerHelper('filter_by_instag', **locals())
out = helper.create_variable_for_type_inference(dtype=ins.dtype)
loss_weight = helper.create_variable_for_type_inference(dtype=np.float64)
mmap = helper.create_variable_for_type_inference(dtype=ins_tag.dtype)
helper.append_op(
type='filter_by_instag',
inputs={'Ins': ins, 'Ins_tag': ins_tag, 'Filter_tag': filter_tag},
outputs={'Out': out, 'LossWeight': loss_weight, 'IndexMap': mmap},
attrs={'is_lod': is_lod, 'out_val_if_empty': out_val_if_empty},
)
return [out, loss_weight]
@deprecated(since='2.0.0', update_to="paddle.expand") @deprecated(since='2.0.0', update_to="paddle.expand")
def expand(x, expand_times, name=None): def expand(x, expand_times, name=None):
""" """
......
...@@ -4284,29 +4284,6 @@ class TestBook(LayerTest): ...@@ -4284,29 +4284,6 @@ class TestBook(LayerTest):
) )
return out return out
def test_filter_by_instag(self):
# TODO(minqiyang): dygraph do not support lod now
with self.static_graph():
x1 = layers.data(
name='Ins', shape=[32, 1], dtype='float32', lod_level=0
)
x2 = layers.data(
name='Ins_tag',
shape=[32, 1],
dtype='int64',
lod_level=0,
stop_gradient=True,
)
x3 = layers.create_global_var(
shape=[1, 1],
value=20,
dtype='int64',
persistable=True,
force_cpu=True,
name='Filter_tag',
)
out1, out2 = layers.filter_by_instag(x1, x2, x3, is_lod=True)
def test_shuffle_batch(self): def test_shuffle_batch(self):
# TODO(minqiyang): dygraph do not support lod now # TODO(minqiyang): dygraph do not support lod now
with self.static_graph(): with self.static_graph():
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册