Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSeg
提交
b23e3ffe
P
PaddleSeg
项目概览
PaddlePaddle
/
PaddleSeg
通知
285
Star
8
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
53
列表
看板
标记
里程碑
合并请求
3
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleSeg
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
53
Issue
53
列表
看板
标记
里程碑
合并请求
3
合并请求
3
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
b23e3ffe
编写于
9月 28, 2020
作者:
M
michaelowenliu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add a component name, remove null return, fix word typo
上级
87043c8b
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
23 addition
and
16 deletion
+23
-16
dygraph/paddleseg/cvlibs/manager.py
dygraph/paddleseg/cvlibs/manager.py
+23
-16
未找到文件。
dygraph/paddleseg/cvlibs/manager.py
浏览文件 @
b23e3ffe
...
@@ -13,21 +13,25 @@
...
@@ -13,21 +13,25 @@
# See the License for the specific language governing permissions and
# See the License for the specific language governing permissions and
# limitations under the License.
# limitations under the License.
from
collections.abc
import
Sequence
import
inspect
import
inspect
from
collections.abc
import
Sequence
class
ComponentManager
:
class
ComponentManager
:
"""
"""
Implement a manager class to add the new component properly.
Implement a manager class to add the new component properly.
The component can be added as either class or function type.
The component can be added as either class or function type.
Args:
name (str): the name of component.
For example:
For example:
>>> model_manager = ComponentManager()
>>> model_manager = ComponentManager()
>>> class AlexNet: ...
>>> class AlexNet: ...
>>> class ResNet: ...
>>> class ResNet: ...
>>> model_manager.add_component(AlexNet)
>>> model_manager.add_component(AlexNet)
>>> model_manager.add_component(ResNet)
>>> model_manager.add_component(ResNet)
or pass a sequence al
liter
atively:
or pass a sequence al
tern
atively:
>>> model_manager.add_component([AlexNet, ResNet])
>>> model_manager.add_component([AlexNet, ResNet])
>>> print(model_manager.components_dict)
>>> print(model_manager.components_dict)
output: {'AlexNet': <class '__main__.AlexNet'>, 'ResNet': <class '__main__.ResNet'>}
output: {'AlexNet': <class '__main__.AlexNet'>, 'ResNet': <class '__main__.ResNet'>}
...
@@ -42,19 +46,21 @@ class ComponentManager:
...
@@ -42,19 +46,21 @@ class ComponentManager:
output: {'AlexNet': <class '__main__.AlexNet'>, 'ResNet': <class '__main__.ResNet'>}
output: {'AlexNet': <class '__main__.AlexNet'>, 'ResNet': <class '__main__.ResNet'>}
"""
"""
def
__init__
(
self
):
def
__init__
(
self
,
name
=
None
):
self
.
_components_dict
=
dict
()
self
.
_components_dict
=
dict
()
self
.
_name
=
name
def
__len__
(
self
):
def
__len__
(
self
):
return
len
(
self
.
_components_dict
)
return
len
(
self
.
_components_dict
)
def
__repr__
(
self
):
def
__repr__
(
self
):
return
"{}:{}"
.
format
(
self
.
__class__
.
__name__
,
name_str
=
self
.
_name
if
self
.
_name
else
self
.
__class__
.
__name__
return
"{}:{}"
.
format
(
name_str
,
list
(
self
.
_components_dict
.
keys
()))
list
(
self
.
_components_dict
.
keys
()))
def
__getitem__
(
self
,
item
):
def
__getitem__
(
self
,
item
):
if
item
not
in
self
.
_components_dict
.
keys
():
if
item
not
in
self
.
_components_dict
.
keys
():
raise
KeyError
(
"{} does not exist in
the current
{}"
.
format
(
raise
KeyError
(
"{} does not exist in
availabel
{}"
.
format
(
item
,
self
))
item
,
self
))
return
self
.
_components_dict
[
item
]
return
self
.
_components_dict
[
item
]
...
@@ -62,15 +68,16 @@ class ComponentManager:
...
@@ -62,15 +68,16 @@ class ComponentManager:
def
components_dict
(
self
):
def
components_dict
(
self
):
return
self
.
_components_dict
return
self
.
_components_dict
@
property
def
name
(
self
):
return
self
.
_name
def
_add_single_component
(
self
,
component
):
def
_add_single_component
(
self
,
component
):
"""
"""
Add a single component into the corresponding manager
Add a single component into the corresponding manager
Args:
Args:
component (function | class): a new component
component (function|class): a new component
Returns:
None
"""
"""
# Currently only support class or function type
# Currently only support class or function type
...
@@ -94,10 +101,10 @@ class ComponentManager:
...
@@ -94,10 +101,10 @@ class ComponentManager:
Add component(s) into the corresponding manager
Add component(s) into the corresponding manager
Args:
Args:
components (function | class | list | tuple): support three
types of components
components (function|class|list|tuple): support four
types of components
Returns:
Returns:
None
components (function|class|list|tuple): same with input components
"""
"""
# Check whether the type is a sequence
# Check whether the type is a sequence
...
@@ -111,8 +118,8 @@ class ComponentManager:
...
@@ -111,8 +118,8 @@ class ComponentManager:
return
components
return
components
MODELS
=
ComponentManager
()
MODELS
=
ComponentManager
(
"models"
)
BACKBONES
=
ComponentManager
()
BACKBONES
=
ComponentManager
(
"backbones"
)
DATASETS
=
ComponentManager
()
DATASETS
=
ComponentManager
(
"datasets"
)
TRANSFORMS
=
ComponentManager
()
TRANSFORMS
=
ComponentManager
(
"transforms"
)
LOSSES
=
ComponentManager
()
LOSSES
=
ComponentManager
(
"losses"
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录