Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
4050ca0e
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
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看板
未验证
提交
4050ca0e
编写于
3月 08, 2023
作者:
L
LoneRanger
提交者:
GitHub
3月 08, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove entry_attr.py and evaluatory.py in fluid (#51330)
* move entry_attr * remove evaluator * fix evaluator
上级
30e0409c
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
0 addition
and
196 deletion
+0
-196
python/paddle/fluid/__init__.py
python/paddle/fluid/__init__.py
+0
-1
python/paddle/fluid/entry_attr.py
python/paddle/fluid/entry_attr.py
+0
-74
python/paddle/fluid/evaluator.py
python/paddle/fluid/evaluator.py
+0
-120
python/paddle/fluid/io.py
python/paddle/fluid/io.py
+0
-1
未找到文件。
python/paddle/fluid/__init__.py
浏览文件 @
4050ca0e
...
...
@@ -51,7 +51,6 @@ from .data import *
from
.
import
trainer_desc
from
.
import
io
from
.
import
evaluator
from
.
import
initializer
from
.initializer
import
set_global_initializer
from
.
import
layers
...
...
python/paddle/fluid/entry_attr.py
已删除
100644 → 0
浏览文件 @
30e0409c
# Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
__all__
=
[
'ProbabilityEntry'
,
'CountFilterEntry'
]
class
EntryAttr
:
"""
Examples:
.. code-block:: python
import paddle.fluid as fluid
"""
def
__init__
(
self
):
self
.
_name
=
None
def
_to_attr
(
self
):
"""
Returns the attributes of this parameter.
Returns:
Parameter attributes(map): The attributes of this parameter.
"""
raise
NotImplementedError
(
"EntryAttr is base class"
)
class
ProbabilityEntry
(
EntryAttr
):
def
__init__
(
self
,
probability
):
super
().
__init__
()
if
not
isinstance
(
probability
,
float
):
raise
ValueError
(
"probability must be a float in (0,1)"
)
if
probability
<=
0
or
probability
>=
1
:
raise
ValueError
(
"probability must be a float in (0,1)"
)
self
.
_name
=
"probability_entry"
self
.
_probability
=
probability
def
_to_attr
(
self
):
return
":"
.
join
([
self
.
_name
,
str
(
self
.
_probability
)])
class
CountFilterEntry
(
EntryAttr
):
def
__init__
(
self
,
count_filter
):
super
().
__init__
()
if
not
isinstance
(
count_filter
,
int
):
raise
ValueError
(
"count_filter must be a valid integer greater than 0"
)
if
count_filter
<
0
:
raise
ValueError
(
"count_filter must be a valid integer greater or equal than 0"
)
self
.
_name
=
"count_filter_entry"
self
.
_count_filter
=
count_filter
def
_to_attr
(
self
):
return
":"
.
join
([
self
.
_name
,
str
(
self
.
_count_filter
)])
python/paddle/fluid/evaluator.py
已删除
100644 → 0
浏览文件 @
30e0409c
# Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import
warnings
import
numpy
as
np
import
paddle
from
.
import
layers
from
.framework
import
Program
,
Variable
,
program_guard
from
.
import
unique_name
from
.layer_helper
import
LayerHelper
def
_clone_var_
(
block
,
var
):
assert
isinstance
(
var
,
Variable
)
return
block
.
create_var
(
name
=
var
.
name
,
shape
=
var
.
shape
,
dtype
=
var
.
dtype
,
type
=
var
.
type
,
lod_level
=
var
.
lod_level
,
persistable
=
True
,
)
class
Evaluator
:
"""
Warning: better to use the fluid.metrics.* things, more
flexible support via pure Python and Operator, and decoupled
with executor. Short doc are intended to urge new user
start from Metrics.
Base Class for all evaluators.
Args:
name(str): The name of evaluator. such as, "accuracy". Used for generate
temporary variable name.
main_program(Program, optional): The evaluator should be added to this
main_program. Default default_main_program()
startup_program(Program, optional):The parameter should be added to this
startup_program. Default default_startup_program()
Attributes:
states(list): The list of state variables. states will be reset to zero
when `reset` is invoked.
metrics(list): The list of metrics variables. They will be calculate
every mini-batch
"""
def
__init__
(
self
,
name
,
**
kwargs
):
warnings
.
warn
(
"The %s is deprecated, because maintain a modified program inside evaluator cause bug easily, please use fluid.metrics.%s instead."
%
(
self
.
__class__
.
__name__
,
self
.
__class__
.
__name__
),
Warning
,
)
self
.
states
=
[]
self
.
metrics
=
[]
self
.
helper
=
LayerHelper
(
name
,
**
kwargs
)
def
reset
(
self
,
executor
,
reset_program
=
None
):
"""
reset metric states at the begin of each pass/user specified batch
Args:
executor(Executor|ParallelExecutor): a executor for executing the reset_program
reset_program(Program): a single Program for reset process
"""
if
reset_program
is
None
:
reset_program
=
Program
()
with
program_guard
(
main_program
=
reset_program
):
for
var
in
self
.
states
:
assert
isinstance
(
var
,
Variable
)
g_var
=
_clone_var_
(
reset_program
.
current_block
(),
var
)
layers
.
fill_constant
(
shape
=
g_var
.
shape
,
value
=
0.0
,
dtype
=
g_var
.
dtype
,
out
=
g_var
)
executor
.
run
(
reset_program
)
def
eval
(
self
,
executor
,
eval_program
=
None
):
"""
Evaluate the statistics merged by multiple mini-batches.
Args:
executor(Executor|ParallelExecutor): a executor for executing the eval_program
eval_program(Program): a single Program for eval process
"""
raise
NotImplementedError
()
def
_create_state
(
self
,
suffix
,
dtype
,
shape
):
"""
Create state variable.
Args:
suffix(str): the state suffix.
dtype(str|core.VarDesc.VarType): the state data type
shape(tuple|list): the shape of state
Returns: State variable
"""
state
=
self
.
helper
.
create_variable
(
name
=
"_"
.
join
([
unique_name
.
generate
(
self
.
helper
.
name
),
suffix
]),
persistable
=
True
,
dtype
=
dtype
,
shape
=
shape
,
)
self
.
states
.
append
(
state
)
return
state
python/paddle/fluid/io.py
浏览文件 @
4050ca0e
...
...
@@ -27,7 +27,6 @@ import math
import
paddle
from
paddle.fluid
import
layers
from
paddle.fluid.executor
import
Executor
,
global_scope
from
paddle.fluid.evaluator
import
Evaluator
from
paddle.fluid.framework
import
(
Program
,
Parameter
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录