Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
ICV-mmengine_basecode
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Florian Schiffel
ICV-mmengine_basecode
Commits
0c59eeab
Unverified
Commit
0c59eeab
authored
2 years ago
by
RangiLyu
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
[Enhance] Refine registry logging info. (#206)
* [Enhance] Refine registry logging info. * update * fix
parent
4742544b
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
mmengine/registry/registry.py
+43
-16
43 additions, 16 deletions
mmengine/registry/registry.py
with
43 additions
and
16 deletions
mmengine/registry/registry.py
+
43
−
16
View file @
0c59eeab
...
@@ -6,6 +6,7 @@ from collections.abc import Callable
...
@@ -6,6 +6,7 @@ from collections.abc import Callable
from
typing
import
Any
,
Dict
,
List
,
Optional
,
Tuple
,
Type
,
Union
from
typing
import
Any
,
Dict
,
List
,
Optional
,
Tuple
,
Type
,
Union
from
..config
import
Config
,
ConfigDict
from
..config
import
Config
,
ConfigDict
from
..logging.logger
import
MMLogger
from
..utils
import
ManagerMixin
,
is_seq_of
from
..utils
import
ManagerMixin
,
is_seq_of
from
.default_scope
import
DefaultScope
from
.default_scope
import
DefaultScope
...
@@ -92,12 +93,23 @@ def build_from_cfg(
...
@@ -92,12 +93,23 @@ def build_from_cfg(
# by `ManagerMixin.get_instance` to ensure that it can be accessed
# by `ManagerMixin.get_instance` to ensure that it can be accessed
# globally.
# globally.
if
issubclass
(
obj_cls
,
ManagerMixin
):
# type: ignore
if
issubclass
(
obj_cls
,
ManagerMixin
):
# type: ignore
return
obj_cls
.
get_instance
(
**
args
)
# type: ignore
obj
=
obj_cls
.
get_instance
(
**
args
)
# type: ignore
else
:
else
:
return
obj_cls
(
**
args
)
# type: ignore
obj
=
obj_cls
(
**
args
)
# type: ignore
logger
:
MMLogger
=
MMLogger
.
get_current_instance
()
logger
.
info
(
f
'
An `
{
obj_cls
.
__name__
}
` instance is built from
'
# type: ignore
f
'
registry, its implementation can be found in
'
f
'
{
obj_cls
.
__module__
}
'
)
# type: ignore
return
obj
except
Exception
as
e
:
except
Exception
as
e
:
# Normal TypeError does not print class name.
# Normal TypeError does not print class name.
raise
type
(
e
)(
f
'
{
obj_cls
.
__name__
}
:
{
e
}
'
)
# type: ignore
cls_location
=
'
/
'
.
join
(
obj_cls
.
__module__
.
split
(
'
.
'
))
# type: ignore
raise
type
(
e
)(
f
'
class `
{
obj_cls
.
__name__
}
` in
'
# type: ignore
f
'
{
cls_location
}
.py:
{
e
}
'
)
class
Registry
:
class
Registry
:
...
@@ -317,27 +329,39 @@ class Registry:
...
@@ -317,27 +329,39 @@ class Registry:
>>>
mobilenet_cls
=
DETECTORS
.
get
(
'
cls.MobileNet
'
)
>>>
mobilenet_cls
=
DETECTORS
.
get
(
'
cls.MobileNet
'
)
"""
"""
scope
,
real_key
=
self
.
split_scope_key
(
key
)
scope
,
real_key
=
self
.
split_scope_key
(
key
)
obj_cls
=
None
registry_name
=
self
.
name
scope_name
=
self
.
scope
if
scope
is
None
or
scope
==
self
.
_scope
:
if
scope
is
None
or
scope
==
self
.
_scope
:
# get from self
# get from self
if
real_key
in
self
.
_module_dict
:
if
real_key
in
self
.
_module_dict
:
return
self
.
_module_dict
[
real_key
]
obj_cls
=
self
.
_module_dict
[
real_key
]
if
scope
is
None
:
el
if
scope
is
None
:
# try to get the target from its parent or ancestors
# try to get the target from its parent or ancestors
parent
=
self
.
parent
parent
=
self
.
parent
while
parent
is
not
None
:
while
parent
is
not
None
:
if
real_key
in
parent
.
_module_dict
:
if
real_key
in
parent
.
_module_dict
:
return
parent
.
_module_dict
[
real_key
]
obj_cls
=
parent
.
_module_dict
[
real_key
]
registry_name
=
parent
.
name
scope_name
=
parent
.
scope
break
parent
=
parent
.
parent
parent
=
parent
.
parent
else
:
else
:
# get from self._children
# get from self._children
if
scope
in
self
.
_children
:
if
scope
in
self
.
_children
:
return
self
.
_children
[
scope
].
get
(
real_key
)
obj_cls
=
self
.
_children
[
scope
].
get
(
real_key
)
registry_name
=
self
.
_children
[
scope
].
name
scope_name
=
scope
else
:
else
:
root
=
self
.
_get_root_registry
()
root
=
self
.
_get_root_registry
()
return
root
.
get
(
key
)
obj_cls
=
root
.
get
(
key
)
if
obj_cls
is
not
None
:
return
None
logger
:
MMLogger
=
MMLogger
.
get_current_instance
()
logger
.
info
(
f
'
Get class `
{
obj_cls
.
__name__
}
` from
"
{
registry_name
}
"'
f
'
registry in
"
{
scope_name
}
"'
)
return
obj_cls
def
_search_child
(
self
,
scope
:
str
)
->
Optional
[
'
Registry
'
]:
def
_search_child
(
self
,
scope
:
str
)
->
Optional
[
'
Registry
'
]:
"""
Depth-first search for the corresponding registry in its children.
"""
Depth-first search for the corresponding registry in its children.
...
@@ -387,16 +411,19 @@ class Registry:
...
@@ -387,16 +411,19 @@ class Registry:
# get the global default scope
# get the global default scope
default_scope
=
DefaultScope
.
get_current_instance
()
default_scope
=
DefaultScope
.
get_current_instance
()
if
default_scope
is
not
None
:
if
default_scope
is
not
None
:
scope_name
=
default_scope
.
scope_name
root
=
self
.
_get_root_registry
()
root
=
self
.
_get_root_registry
()
registry
=
root
.
_search_child
(
default_scope
.
scope_name
)
registry
=
root
.
_search_child
(
scope_name
)
if
registry
is
None
:
if
registry
is
None
:
# if `default_scope` can not be found, fallback to use self
# if `default_scope` can not be found, fallback to use self
warnings
.
warn
(
warnings
.
warn
(
f
'
Failed to search registry named
"
{
default_scope
}
"
.
'
f
'
Failed to search registry with scope
"
{
scope_name
}
"
in
'
'
As a workaround, the current registry is used to build
'
f
'
the
"
{
root
.
name
}
"
registry tree.
'
'
instance. This may cause unexpected failure when running
'
f
'
As a workaround, the current
"
{
self
.
name
}
"
registry in
'
'
the built modules. Please check whether
'
f
'"
{
self
.
scope
}
"
is used to build instance. This may
'
f
'"
{
default_scope
}
"
is a correct scope.
'
)
f
'
cause unexpected failure when running the built
'
f
'
modules. Please check whether
"
{
scope_name
}
"
is a
'
f
'
correct scope, or whether the registry is initialized.
'
)
registry
=
self
registry
=
self
else
:
else
:
registry
=
self
registry
=
self
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment