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
MMCV
Commits
b7c924cb
Commit
b7c924cb
authored
Apr 21, 2019
by
Kai Chen
Browse files
use collections.abc instead of collections
parent
944da49f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
9 deletions
+15
-9
mmcv/utils/config.py
mmcv/utils/config.py
+2
-2
mmcv/utils/misc.py
mmcv/utils/misc.py
+8
-2
mmcv/utils/progressbar.py
mmcv/utils/progressbar.py
+5
-5
No files found.
mmcv/utils/config.py
View file @
b7c924cb
import
os.path
as
osp
import
os.path
as
osp
import
sys
import
sys
from
argparse
import
ArgumentParser
from
argparse
import
ArgumentParser
from
collections
import
Iterable
from
importlib
import
import_module
from
importlib
import
import_module
from
addict
import
Dict
from
addict
import
Dict
from
.misc
import
collections_abc
from
.path
import
check_file_exist
from
.path
import
check_file_exist
...
@@ -39,7 +39,7 @@ def add_args(parser, cfg, prefix=''):
...
@@ -39,7 +39,7 @@ def add_args(parser, cfg, prefix=''):
parser
.
add_argument
(
'--'
+
prefix
+
k
,
action
=
'store_true'
)
parser
.
add_argument
(
'--'
+
prefix
+
k
,
action
=
'store_true'
)
elif
isinstance
(
v
,
dict
):
elif
isinstance
(
v
,
dict
):
add_args
(
parser
,
v
,
k
+
'.'
)
add_args
(
parser
,
v
,
k
+
'.'
)
elif
isinstance
(
v
,
Iterable
):
elif
isinstance
(
v
,
collections_abc
.
Iterable
):
parser
.
add_argument
(
'--'
+
prefix
+
k
,
type
=
type
(
v
[
0
]),
nargs
=
'+'
)
parser
.
add_argument
(
'--'
+
prefix
+
k
,
type
=
type
(
v
[
0
]),
nargs
=
'+'
)
else
:
else
:
print
(
'connot parse key {} of type {}'
.
format
(
prefix
+
k
,
type
(
v
)))
print
(
'connot parse key {} of type {}'
.
format
(
prefix
+
k
,
type
(
v
)))
...
...
mmcv/utils/misc.py
View file @
b7c924cb
...
@@ -3,6 +3,12 @@ import functools
...
@@ -3,6 +3,12 @@ import functools
import
itertools
import
itertools
import
subprocess
import
subprocess
from
importlib
import
import_module
from
importlib
import
import_module
# ABCs from collections will be deprecated in python 3.8+,
# while collections.abc is not available in python 2.7
try
:
import
collections.abc
as
collections_abc
except
ImportError
:
import
collections
as
collections_abc
import
six
import
six
...
@@ -24,7 +30,7 @@ def iter_cast(inputs, dst_type, return_type=None):
...
@@ -24,7 +30,7 @@ def iter_cast(inputs, dst_type, return_type=None):
Returns:
Returns:
iterator or specified type: The converted object.
iterator or specified type: The converted object.
"""
"""
if
not
isinstance
(
inputs
,
collections
.
Iterable
):
if
not
isinstance
(
inputs
,
collections
_abc
.
Iterable
):
raise
TypeError
(
'inputs must be an iterable object'
)
raise
TypeError
(
'inputs must be an iterable object'
)
if
not
isinstance
(
dst_type
,
type
):
if
not
isinstance
(
dst_type
,
type
):
raise
TypeError
(
'"dst_type" must be a valid type'
)
raise
TypeError
(
'"dst_type" must be a valid type'
)
...
@@ -65,7 +71,7 @@ def is_seq_of(seq, expected_type, seq_type=None):
...
@@ -65,7 +71,7 @@ def is_seq_of(seq, expected_type, seq_type=None):
bool: Whether the sequence is valid.
bool: Whether the sequence is valid.
"""
"""
if
seq_type
is
None
:
if
seq_type
is
None
:
exp_seq_type
=
collections
.
Sequence
exp_seq_type
=
collections
_abc
.
Sequence
else
:
else
:
assert
isinstance
(
seq_type
,
type
)
assert
isinstance
(
seq_type
,
type
)
exp_seq_type
=
seq_type
exp_seq_type
=
seq_type
...
...
mmcv/utils/progressbar.py
View file @
b7c924cb
import
collections
import
sys
import
sys
from
multiprocessing
import
Pool
from
multiprocessing
import
Pool
from
.misc
import
collections_abc
from
.timer
import
Timer
from
.timer
import
Timer
...
@@ -76,11 +76,11 @@ def track_progress(func, tasks, bar_width=50, **kwargs):
...
@@ -76,11 +76,11 @@ def track_progress(func, tasks, bar_width=50, **kwargs):
"""
"""
if
isinstance
(
tasks
,
tuple
):
if
isinstance
(
tasks
,
tuple
):
assert
len
(
tasks
)
==
2
assert
len
(
tasks
)
==
2
assert
isinstance
(
tasks
[
0
],
collections
.
Iterable
)
assert
isinstance
(
tasks
[
0
],
collections
_abc
.
Iterable
)
assert
isinstance
(
tasks
[
1
],
int
)
assert
isinstance
(
tasks
[
1
],
int
)
task_num
=
tasks
[
1
]
task_num
=
tasks
[
1
]
tasks
=
tasks
[
0
]
tasks
=
tasks
[
0
]
elif
isinstance
(
tasks
,
collections
.
Iterable
):
elif
isinstance
(
tasks
,
collections
_abc
.
Iterable
):
task_num
=
len
(
tasks
)
task_num
=
len
(
tasks
)
else
:
else
:
raise
TypeError
(
raise
TypeError
(
...
@@ -141,11 +141,11 @@ def track_parallel_progress(func,
...
@@ -141,11 +141,11 @@ def track_parallel_progress(func,
"""
"""
if
isinstance
(
tasks
,
tuple
):
if
isinstance
(
tasks
,
tuple
):
assert
len
(
tasks
)
==
2
assert
len
(
tasks
)
==
2
assert
isinstance
(
tasks
[
0
],
collections
.
Iterable
)
assert
isinstance
(
tasks
[
0
],
collections
_abc
.
Iterable
)
assert
isinstance
(
tasks
[
1
],
int
)
assert
isinstance
(
tasks
[
1
],
int
)
task_num
=
tasks
[
1
]
task_num
=
tasks
[
1
]
tasks
=
tasks
[
0
]
tasks
=
tasks
[
0
]
elif
isinstance
(
tasks
,
collections
.
Iterable
):
elif
isinstance
(
tasks
,
collections
_abc
.
Iterable
):
task_num
=
len
(
tasks
)
task_num
=
len
(
tasks
)
else
:
else
:
raise
TypeError
(
raise
TypeError
(
...
...
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