Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
468f8815
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
468f8815
编写于
11月 21, 2022
作者:
傅
傅剑寒
提交者:
GitHub
11月 21, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
(fluid清理)Remove filter by instag in nn.py under fluid (#47929)
上级
27e252d9
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
1 addition
and
94 deletion
+1
-94
python/paddle/fluid/layers/nn.py
python/paddle/fluid/layers/nn.py
+1
-71
python/paddle/fluid/tests/unittests/test_layers.py
python/paddle/fluid/tests/unittests/test_layers.py
+0
-23
未找到文件。
python/paddle/fluid/layers/nn.py
浏览文件 @
468f8815
...
...
@@ -23,7 +23,7 @@ import numpy as np
import paddle
from ..layer_helper import LayerHelper
from paddle.fluid.framework import _in_legacy_dygraph
from ..initializer import Normal, Constant
, NumpyArrayInitializer
from ..initializer import Normal, Constant
from ..framework import (
Variable,
OpProtoHolder,
...
...
@@ -182,7 +182,6 @@ __all__ = [
'sign',
'unfold',
'deformable_roi_pooling',
'filter_by_instag',
'shard_index',
'hard_swish',
'mish',
...
...
@@ -9951,75 +9950,6 @@ def flatten(x, axis=1, name=None):
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")
def expand(x, expand_times, name=None):
"""
...
...
python/paddle/fluid/tests/unittests/test_layers.py
浏览文件 @
468f8815
...
...
@@ -4284,29 +4284,6 @@ class TestBook(LayerTest):
)
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
):
# TODO(minqiyang): dygraph do not support lod now
with
self
.
static_graph
():
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录