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
fe07f09e
Unverified
Commit
fe07f09e
authored
Sep 03, 2020
by
Wang Xinjiang
Committed by
GitHub
Sep 03, 2020
Browse files
Add more default types for json dump (#536)
parent
8dfe58d1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
1 deletion
+5
-1
mmcv/fileio/handlers/json_handler.py
mmcv/fileio/handlers/json_handler.py
+5
-1
No files found.
mmcv/fileio/handlers/json_handler.py
View file @
fe07f09e
...
...
@@ -10,12 +10,16 @@ def set_default(obj):
"""Set default json values for non-serializable values.
It helps convert ``set``, ``range`` and ``np.ndarray`` data types to list.
It also converts ``np.generic`` (including ``np.int32``, ``np.float32``,
etc.) into plain numbers of plain python built-in types.
"""
if
isinstance
(
obj
,
(
set
,
range
)):
return
list
(
obj
)
elif
isinstance
(
obj
,
np
.
ndarray
):
return
obj
.
tolist
()
raise
TypeError
elif
isinstance
(
obj
,
np
.
generic
):
return
obj
.
item
()
raise
TypeError
(
f
'
{
type
(
obj
)
}
is unsupported for json dump'
)
class
JsonHandler
(
BaseFileHandler
):
...
...
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