Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MindSpore
mindinsight
提交
7936eaf2
M
mindinsight
项目概览
MindSpore
/
mindinsight
通知
7
Star
3
Fork
2
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindinsight
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7936eaf2
编写于
4月 22, 2020
作者:
M
mindspore-ci-bot
提交者:
Gitee
4月 22, 2020
浏览文件
操作
浏览文件
下载
差异文件
!63 add comments, optimize histogram log generator to record max and min
Merge pull request !63 from wenkai/wk0422_2
上级
e63cc721
5c6fb358
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
130 addition
and
114 deletion
+130
-114
mindinsight/datavisual/data_transform/histogram_container.py
mindinsight/datavisual/data_transform/histogram_container.py
+7
-0
mindinsight/datavisual/data_transform/reservoir.py
mindinsight/datavisual/data_transform/reservoir.py
+4
-0
tests/utils/log_generators/histogram_log_generator.py
tests/utils/log_generators/histogram_log_generator.py
+119
-114
未找到文件。
mindinsight/datavisual/data_transform/histogram_container.py
浏览文件 @
7936eaf2
...
@@ -120,6 +120,13 @@ class HistogramContainer:
...
@@ -120,6 +120,13 @@ class HistogramContainer:
It's caller's duty to ensure input is valid.
It's caller's duty to ensure input is valid.
Why we need visual range for histograms? Miss aligned buckets between steps might miss-lead users about the
trend of a tensor. Because for given tensor, if you have thinner buckets, count of every bucket might get
low, however, if you have thicker buckets, count of every bucket might get high. If there are the above two
kinds of histogram in one graph, user might think the histogram with thicker buckets has more values. This is
miss-leading. So we need to unify buckets across steps. Visual range for histogram is a technology for unifying
buckets.
Args:
Args:
max_val (float): Max value for visual histogram.
max_val (float): Max value for visual histogram.
min_val (float): Min value for visual histogram.
min_val (float): Min value for visual histogram.
...
...
mindinsight/datavisual/data_transform/reservoir.py
浏览文件 @
7936eaf2
...
@@ -172,6 +172,10 @@ class HistogramReservoir(Reservoir):
...
@@ -172,6 +172,10 @@ class HistogramReservoir(Reservoir):
max_count
=
max
(
histogram
.
count
,
max_count
)
max_count
=
max
(
histogram
.
count
,
max_count
)
visual_range
.
update
(
histogram
.
max
,
histogram
.
min
)
visual_range
.
update
(
histogram
.
max
,
histogram
.
min
)
if
visual_range
.
max
==
visual_range
.
min
and
not
max_count
:
logger
.
warning
(
"Max equals to min, however, count is zero. Please check mindspore "
"does write max and min values to histogram summary file."
)
bins
=
calc_histogram_bins
(
max_count
)
bins
=
calc_histogram_bins
(
max_count
)
# update visual range
# update visual range
...
...
tests/utils/log_generators/histogram_log_generator.py
浏览文件 @
7936eaf2
# Copyright 2020 Huawei Technologies Co., Ltd
# Copyright 2020 Huawei Technologies Co., Ltd
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing, software
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# See the License for the specific language governing permissions and
# limitations under the License.
# limitations under the License.
# ============================================================================
# ============================================================================
"""Log generator for histogram data."""
"""Log generator for histogram data."""
import
time
import
time
import
numpy
as
np
import
numpy
as
np
from
mindinsight.datavisual.proto_files
import
mindinsight_summary_pb2
as
summary_pb2
from
mindinsight.datavisual.proto_files
import
mindinsight_summary_pb2
as
summary_pb2
from
.log_generator
import
LogGenerator
from
.log_generator
import
LogGenerator
class
HistogramLogGenerator
(
LogGenerator
):
class
HistogramLogGenerator
(
LogGenerator
):
"""
"""
Log generator for histogram data.
Log generator for histogram data.
This is a log generator writing histogram data. User can use it to generate fake
This is a log generator writing histogram data. User can use it to generate fake
summary logs about histogram.
summary logs about histogram.
"""
"""
def
generate_event
(
self
,
values
):
def
generate_event
(
self
,
values
):
"""
"""
Method for generating histogram event.
Method for generating histogram event.
Args:
Args:
values (dict): A dict contains:
values (dict): A dict contains:
{
{
wall_time (float): Timestamp.
wall_time (float): Timestamp.
step (int): Train step.
step (int): Train step.
value (float): Histogram value.
value (float): Histogram value.
tag (str): Tag name.
tag (str): Tag name.
}
}
Returns:
Returns:
summary_pb2.Event.
summary_pb2.Event.
"""
"""
histogram_event
=
summary_pb2
.
Event
()
histogram_event
=
summary_pb2
.
Event
()
histogram_event
.
wall_time
=
values
.
get
(
'wall_time'
)
histogram_event
.
wall_time
=
values
.
get
(
'wall_time'
)
histogram_event
.
step
=
values
.
get
(
'step'
)
histogram_event
.
step
=
values
.
get
(
'step'
)
value
=
histogram_event
.
summary
.
value
.
add
()
value
=
histogram_event
.
summary
.
value
.
add
()
value
.
tag
=
values
.
get
(
'tag'
)
value
.
tag
=
values
.
get
(
'tag'
)
buckets
=
values
.
get
(
'buckets'
)
buckets
=
values
.
get
(
'buckets'
)
for
bucket
in
buckets
:
for
bucket
in
buckets
:
left
,
width
,
count
=
bucket
left
,
width
,
count
=
bucket
bucket
=
value
.
histogram
.
buckets
.
add
()
bucket
=
value
.
histogram
.
buckets
.
add
()
bucket
.
left
=
left
bucket
.
left
=
left
bucket
.
width
=
width
bucket
.
width
=
width
bucket
.
count
=
count
bucket
.
count
=
count
return
histogram_event
value
.
histogram
.
min
=
values
.
get
(
"min"
,
-
1
)
value
.
histogram
.
max
=
values
.
get
(
"max"
,
-
1
)
def
generate_log
(
self
,
file_path
,
steps_list
,
tag_name
):
"""
return
histogram_event
Generate log for external calls.
def
generate_log
(
self
,
file_path
,
steps_list
,
tag_name
):
Args:
"""
file_path (str): Path to write logs.
Generate log for external calls.
steps_list (list): A list consists of step.
tag_name (str): Tag name.
Args:
file_path (str): Path to write logs.
Returns:
steps_list (list): A list consists of step.
list[dict], generated histogram metadata.
tag_name (str): Tag name.
None, to be consistent with return value of HistogramGenerator.
Returns:
"""
list[dict], generated histogram metadata.
histogram_metadata
=
[]
None, to be consistent with return value of HistogramGenerator.
for
step
in
steps_list
:
histogram
=
dict
()
"""
histogram_metadata
=
[]
wall_time
=
time
.
time
()
for
step
in
steps_list
:
histogram
.
update
({
'wall_time'
:
wall_time
})
histogram
=
dict
()
histogram
.
update
({
'step'
:
step
})
histogram
.
update
({
'tag'
:
tag_name
})
wall_time
=
time
.
time
()
histogram
.
update
({
'wall_time'
:
wall_time
})
# Construct buckets
histogram
.
update
({
'step'
:
step
})
buckets
=
[]
histogram
.
update
({
'tag'
:
tag_name
})
leftmost
=
list
(
np
.
random
.
randn
(
11
))
leftmost
.
sort
()
# Construct buckets
for
i
in
range
(
10
):
buckets
=
[]
left
=
leftmost
[
i
]
leftmost
=
list
(
np
.
random
.
randn
(
11
))
width
=
leftmost
[
i
+
1
]
-
left
leftmost
.
sort
()
count
=
np
.
random
.
randint
(
20
)
min_val
=
leftmost
[
0
]
bucket
=
[
left
,
width
,
count
]
max_val
=
leftmost
[
-
1
]
buckets
.
append
(
bucket
)
for
i
in
range
(
10
):
left
=
leftmost
[
i
]
histogram
.
update
({
'buckets'
:
buckets
})
width
=
leftmost
[
i
+
1
]
-
left
histogram_metadata
.
append
(
histogram
)
count
=
np
.
random
.
randint
(
20
)
bucket
=
[
left
,
width
,
count
]
self
.
_write_log_one_step
(
file_path
,
histogram
)
buckets
.
append
(
bucket
)
return
histogram_metadata
,
None
histogram
.
update
({
'buckets'
:
buckets
,
"min"
:
min_val
,
"max"
:
max_val
})
histogram_metadata
.
append
(
histogram
)
if
__name__
==
"__main__"
:
self
.
_write_log_one_step
(
file_path
,
histogram
)
histogram_log_generator
=
HistogramLogGenerator
()
test_file_name
=
'%s.%s.%s'
%
(
'histogram'
,
'summary'
,
str
(
time
.
time
()))
return
histogram_metadata
,
None
test_steps
=
[
1
,
3
,
5
]
test_tag
=
"test_histogram_tag_name"
histogram_log_generator
.
generate_log
(
test_file_name
,
test_steps
,
test_tag
)
if
__name__
==
"__main__"
:
histogram_log_generator
=
HistogramLogGenerator
()
test_file_name
=
'%s.%s.%s'
%
(
'histogram'
,
'summary'
,
str
(
time
.
time
()))
test_steps
=
[
1
,
3
,
5
]
test_tag
=
"test_histogram_tag_name"
histogram_log_generator
.
generate_log
(
test_file_name
,
test_steps
,
test_tag
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录