Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
mmdetection3d
Commits
928aa884
You need to sign in or sign up before continuing.
Commit
928aa884
authored
Jun 15, 2022
by
VVsssssk
Committed by
ChaimZhu
Jul 20, 2022
Browse files
[Fix]Fix train.py and registe all model
parent
ccf028f7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
13 deletions
+25
-13
mmdet3d/utils/setup_env.py
mmdet3d/utils/setup_env.py
+19
-2
tools/train.py
tools/train.py
+6
-11
No files found.
mmdet3d/utils/setup_env.py
View file @
928aa884
# Copyright (c) OpenMMLab. All rights reserved.
# Copyright (c) OpenMMLab. All rights reserved.
import
datetime
import
os
import
os
import
platform
import
platform
import
warnings
import
warnings
...
@@ -58,7 +59,7 @@ def register_all_modules(init_default_scope: bool = True) -> None:
...
@@ -58,7 +59,7 @@ def register_all_modules(init_default_scope: bool = True) -> None:
"""Register all modules in mmdet3d into the registries.
"""Register all modules in mmdet3d into the registries.
Args:
Args:
init_default_scope (bool): Whether initialize the mmdet
3d
default scope.
init_default_scope (bool): Whether initialize the mmdet default scope.
When `init_default_scope=True`, the global default scope will be
When `init_default_scope=True`, the global default scope will be
set to `mmdet3d`, and all registries will build modules from mmdet3d's
set to `mmdet3d`, and all registries will build modules from mmdet3d's
registry node. To understand more about the registry, please refer
registry node. To understand more about the registry, please refer
...
@@ -67,7 +68,23 @@ def register_all_modules(init_default_scope: bool = True) -> None:
...
@@ -67,7 +68,23 @@ def register_all_modules(init_default_scope: bool = True) -> None:
"""
# noqa
"""
# noqa
import
mmdet3d.core
# noqa: F401,F403
import
mmdet3d.core
# noqa: F401,F403
import
mmdet3d.datasets
# noqa: F401,F403
import
mmdet3d.datasets
# noqa: F401,F403
import
mmdet3d.metrics
# noqa: F401,F403
import
mmdet3d.models
# noqa: F401,F403
import
mmdet3d.models
# noqa: F401,F403
import
mmdet3d.ops
# noqa: F401,F403
import
mmdet3d.ops
# noqa: F401,F403
import
mmdet3d.scheduler
# noqa: F401,F403
if
init_default_scope
:
if
init_default_scope
:
DefaultScope
.
get_instance
(
'mmdet3d'
,
scope_name
=
'mmdet3d'
)
never_created
=
DefaultScope
.
get_current_instance
()
is
None
\
or
not
DefaultScope
.
check_instance_created
(
'mmdet3d'
)
if
never_created
:
DefaultScope
.
get_instance
(
'mmdet3d'
,
scope_name
=
'mmdet3d'
)
return
current_scope
=
DefaultScope
.
get_current_instance
()
if
current_scope
.
scope_name
!=
'mmdet3d'
:
warnings
.
warn
(
'The current default scope '
f
'"
{
current_scope
.
scope_name
}
" is not "mmdet3d", '
'`register_all_modules` will force the current'
'default scope to be "mmdet3d". If this is not '
'expected, please set `init_default_scope=False`.'
)
# avoid name conflict
new_instance_name
=
f
'mmdet3d-
{
datetime
.
datetime
.
now
()
}
'
DefaultScope
.
get_instance
(
new_instance_name
,
scope_name
=
'mmdet3d'
)
tools/train.py
View file @
928aa884
# Copyright (c) OpenMMLab. All rights reserved.
# Copyright (c) OpenMMLab. All rights reserved.
from
__future__
import
division
import
argparse
import
argparse
import
os
import
os
from
os
import
path
as
osp
import
os.
path
as
osp
from
mm
cv
import
Config
,
DictAction
from
mm
engine.config
import
Config
,
DictAction
from
mmengine
import
Runner
from
mmengine
.runner
import
Runner
from
mmdet3d.utils
import
register_all_modules
from
mmdet3d.utils
import
register_all_modules
def
parse_args
():
def
parse_args
():
parser
=
argparse
.
ArgumentParser
(
description
=
'Train a detector'
)
parser
=
argparse
.
ArgumentParser
(
description
=
'Train a
3D
detector'
)
parser
.
add_argument
(
'config'
,
help
=
'train config file path'
)
parser
.
add_argument
(
'config'
,
help
=
'train config file path'
)
parser
.
add_argument
(
'--work-dir'
,
help
=
'the dir to save logs and models'
)
parser
.
add_argument
(
'--work-dir'
,
help
=
'the dir to save logs and models'
)
parser
.
add_argument
(
parser
.
add_argument
(
...
@@ -33,21 +32,19 @@ def parse_args():
...
@@ -33,21 +32,19 @@ def parse_args():
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
if
'LOCAL_RANK'
not
in
os
.
environ
:
if
'LOCAL_RANK'
not
in
os
.
environ
:
os
.
environ
[
'LOCAL_RANK'
]
=
str
(
args
.
local_rank
)
os
.
environ
[
'LOCAL_RANK'
]
=
str
(
args
.
local_rank
)
return
args
return
args
def
main
():
def
main
():
args
=
parse_args
()
args
=
parse_args
()
# register all modules in mmdet3d into the registries
# register all modules in mmdet3d into the registries
# do not init the default scope here because it will be init in the runner
# do not init the default scope here because it will be init in the runner
register_all_modules
(
init_default_scope
=
False
)
register_all_modules
(
init_default_scope
=
False
)
# load config
cfg
=
Config
.
fromfile
(
args
.
config
)
cfg
=
Config
.
fromfile
(
args
.
config
)
cfg
.
launcher
=
args
.
launcher
if
args
.
cfg_options
is
not
None
:
if
args
.
cfg_options
is
not
None
:
cfg
.
merge_from_dict
(
args
.
cfg_options
)
cfg
.
merge_from_dict
(
args
.
cfg_options
)
# work_dir is determined in this priority: CLI > segment in file > filename
# work_dir is determined in this priority: CLI > segment in file > filename
if
args
.
work_dir
is
not
None
:
if
args
.
work_dir
is
not
None
:
# update configs according to CLI args if args.work_dir is not None
# update configs according to CLI args if args.work_dir is not None
...
@@ -56,10 +53,8 @@ def main():
...
@@ -56,10 +53,8 @@ def main():
# use config filename as default work_dir if cfg.work_dir is None
# use config filename as default work_dir if cfg.work_dir is None
cfg
.
work_dir
=
osp
.
join
(
'./work_dirs'
,
cfg
.
work_dir
=
osp
.
join
(
'./work_dirs'
,
osp
.
splitext
(
osp
.
basename
(
args
.
config
))[
0
])
osp
.
splitext
(
osp
.
basename
(
args
.
config
))[
0
])
# build the runner from config
# build the runner from config
runner
=
Runner
.
from_cfg
(
cfg
)
runner
=
Runner
.
from_cfg
(
cfg
)
# start training
# start training
runner
.
train
()
runner
.
train
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment