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
ea61bf6b
Unverified
Commit
ea61bf6b
authored
2 years ago
by
Mashiro
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix: avoid modification of scalar_dict in LocalVisBackend (#377)
parent
5b648c11
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
mmengine/visualization/vis_backend.py
+4
-1
4 additions, 1 deletion
mmengine/visualization/vis_backend.py
tests/test_visualizer/test_vis_backend.py
+14
-1
14 additions, 1 deletion
tests/test_visualizer/test_vis_backend.py
with
18 additions
and
2 deletions
mmengine/visualization/vis_backend.py
+
4
−
1
View file @
ea61bf6b
# Copyright (c) OpenMMLab. All rights reserved.
import
copy
import
functools
import
os
import
os.path
as
osp
...
...
@@ -291,6 +292,7 @@ class LocalVisBackend(BaseVisBackend):
Default to None.
"""
assert
isinstance
(
scalar_dict
,
dict
)
scalar_dict
=
copy
.
deepcopy
(
scalar_dict
)
scalar_dict
.
setdefault
(
'
step
'
,
step
)
if
file_path
is
not
None
:
...
...
@@ -542,7 +544,8 @@ class TensorboardVisBackend(BaseVisBackend):
value (int, float, torch.Tensor, np.ndarray): Value to save.
step (int): Global step value to record. Default to 0.
"""
if
isinstance
(
value
,
(
int
,
float
,
torch
.
Tensor
,
np
.
ndarray
)):
if
isinstance
(
value
,
(
int
,
float
,
torch
.
Tensor
,
np
.
ndarray
,
np
.
number
)):
self
.
_tensorboard
.
add_scalar
(
name
,
value
,
step
)
else
:
warnings
.
warn
(
f
'
Got
{
type
(
value
)
}
, but numpy array, torch tensor,
'
...
...
This diff is collapsed.
Click to expand it.
tests/test_visualizer/test_vis_backend.py
+
14
−
1
View file @
ea61bf6b
...
...
@@ -86,6 +86,7 @@ class TestLocalVisBackend:
input_dict
=
{
'
map
'
:
0.7
,
'
acc
'
:
0.9
}
local_vis_backend
=
LocalVisBackend
(
'
temp_dir
'
)
local_vis_backend
.
add_scalars
(
input_dict
)
assert
input_dict
==
{
'
map
'
:
0.7
,
'
acc
'
:
0.9
}
out_dict
=
load
(
local_vis_backend
.
_scalar_save_file
,
'
json
'
)
assert
out_dict
==
{
'
map
'
:
0.7
,
'
acc
'
:
0.9
,
'
step
'
:
0
}
...
...
@@ -143,7 +144,19 @@ class TestTensorboardVisBackend:
# test append mode
tensorboard_vis_backend
.
add_scalar
(
'
map
'
,
0.9
,
step
=
0
)
tensorboard_vis_backend
.
add_scalar
(
'
map
'
,
0.95
,
step
=
1
)
# test with numpy
with
pytest
.
warns
(
None
)
as
record
:
tensorboard_vis_backend
.
add_scalar
(
'
map
'
,
np
.
array
(
0.9
),
step
=
0
)
tensorboard_vis_backend
.
add_scalar
(
'
map
'
,
np
.
array
(
0.95
),
step
=
1
)
tensorboard_vis_backend
.
add_scalar
(
'
map
'
,
np
.
array
(
9
),
step
=
0
)
tensorboard_vis_backend
.
add_scalar
(
'
map
'
,
np
.
array
(
95
),
step
=
1
)
tensorboard_vis_backend
.
add_scalar
(
'
map
'
,
np
.
array
([
9
])[
0
],
step
=
0
)
tensorboard_vis_backend
.
add_scalar
(
'
map
'
,
np
.
array
([
95
])[
0
],
step
=
1
)
assert
len
(
record
)
==
0
# test with tensor
tensorboard_vis_backend
.
add_scalar
(
'
map
'
,
torch
.
tensor
(
0.9
),
step
=
0
)
tensorboard_vis_backend
.
add_scalar
(
'
map
'
,
torch
.
tensor
(
0.95
),
step
=
1
)
# Unprocessable data will output a warning message
with
pytest
.
warns
(
Warning
):
tensorboard_vis_backend
.
add_scalar
(
'
map
'
,
[
0.95
])
...
...
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