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
95a9728c
"git@developer.sourcefind.cn:renzhc/diffusers_dcu.git" did not exist on "8eb17315c8824e256dcc81bff254fa1cdfba49d9"
Unverified
Commit
95a9728c
authored
Aug 21, 2020
by
Kevin
Committed by
GitHub
Aug 21, 2020
Browse files
Support pickle.loads (#499) (#500)
parent
77c03f44
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
1 deletion
+22
-1
mmcv/utils/config.py
mmcv/utils/config.py
+9
-0
tests/test_config.py
tests/test_config.py
+13
-1
No files found.
mmcv/utils/config.py
View file @
95a9728c
...
@@ -372,6 +372,15 @@ class Config:
...
@@ -372,6 +372,15 @@ class Config:
def
__iter__
(
self
):
def
__iter__
(
self
):
return
iter
(
self
.
_cfg_dict
)
return
iter
(
self
.
_cfg_dict
)
def
__getstate__
(
self
):
return
(
self
.
_cfg_dict
,
self
.
_filename
,
self
.
_text
)
def
__setstate__
(
self
,
state
):
_cfg_dict
,
_filename
,
_text
=
state
super
(
Config
,
self
).
__setattr__
(
'_cfg_dict'
,
_cfg_dict
)
super
(
Config
,
self
).
__setattr__
(
'_filename'
,
_filename
)
super
(
Config
,
self
).
__setattr__
(
'_text'
,
_text
)
def
dump
(
self
,
file
=
None
):
def
dump
(
self
,
file
=
None
):
cfg_dict
=
super
(
Config
,
self
).
__getattribute__
(
'_cfg_dict'
).
to_dict
()
cfg_dict
=
super
(
Config
,
self
).
__getattribute__
(
'_cfg_dict'
).
to_dict
()
if
self
.
filename
.
endswith
(
'.py'
):
if
self
.
filename
.
endswith
(
'.py'
):
...
...
tests/test_config.py
View file @
95a9728c
...
@@ -7,7 +7,7 @@ import tempfile
...
@@ -7,7 +7,7 @@ import tempfile
import
pytest
import
pytest
import
yaml
import
yaml
from
mmcv
import
Config
,
DictAction
from
mmcv
import
Config
,
DictAction
,
dump
,
load
def
test_construct
():
def
test_construct
():
...
@@ -354,3 +354,15 @@ def test_syntax_error():
...
@@ -354,3 +354,15 @@ def test_syntax_error():
f
'file
{
temp_cfg_path
}
'
):
f
'file
{
temp_cfg_path
}
'
):
Config
.
fromfile
(
temp_cfg_path
)
Config
.
fromfile
(
temp_cfg_path
)
temp_cfg_file
.
close
()
temp_cfg_file
.
close
()
def
test_pickle_support
():
cfg_file
=
osp
.
join
(
osp
.
dirname
(
__file__
),
'data/config/n.py'
)
cfg
=
Config
.
fromfile
(
cfg_file
)
with
tempfile
.
TemporaryDirectory
()
as
temp_config_dir
:
pkl_cfg_filename
=
osp
.
join
(
temp_config_dir
,
'_pickle.pkl'
)
dump
(
cfg
,
pkl_cfg_filename
)
pkl_cfg
=
load
(
pkl_cfg_filename
)
assert
pkl_cfg
.
_cfg_dict
==
cfg
.
_cfg_dict
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