Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
正统之独孤求败
mindspore
提交
62418143
M
mindspore
项目概览
正统之独孤求败
/
mindspore
与 Fork 源项目一致
Fork自
MindSpore / mindspore
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindspore
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
62418143
编写于
4月 29, 2020
作者:
M
mindspore-ci-bot
提交者:
Gitee
4月 29, 2020
浏览文件
操作
浏览文件
下载
差异文件
!749 fix np.histogram sometimes calc very large bucket number
Merge pull request !749 from wenkai/wkmaster
上级
e64f806a
ab04b3dc
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
35 addition
and
2 deletion
+35
-2
mindspore/train/summary/_summary_adapter.py
mindspore/train/summary/_summary_adapter.py
+33
-1
tests/ut/python/train/summary/test_histogram_summary.py
tests/ut/python/train/summary/test_histogram_summary.py
+2
-1
未找到文件。
mindspore/train/summary/_summary_adapter.py
浏览文件 @
62418143
...
...
@@ -15,6 +15,7 @@
"""Generate the summary event which conform to proto format."""
import
time
import
socket
import
math
from
enum
import
Enum
,
unique
import
numpy
as
np
from
PIL
import
Image
...
...
@@ -292,6 +293,36 @@ def _get_tensor_summary(tag: str, np_value, summary_tensor):
return
summary_tensor
def
_calc_histogram_bins
(
count
):
"""
Calculates experience-based optimal bins number for histogram.
There should be enough number in each bin. So we calc bin numbers according to count. For very small count(1 -
10), we assign carefully chosen number. For large count, we tried to make sure there are 9-10 numbers in each
bucket on average. Too many bins will slow down performance, so we set max number of bins to 90.
Args:
count (int): Valid number count for the tensor.
Returns:
int, number of histogram bins.
"""
number_per_bucket
=
10
max_bins
=
90
if
not
count
:
return
1
if
count
<=
5
:
return
2
if
count
<=
10
:
return
3
if
count
<=
880
:
# note that math.ceil(881/10) + 1 equals 90
return
int
(
math
.
ceil
(
count
/
number_per_bucket
)
+
1
)
return
max_bins
def
_fill_histogram_summary
(
tag
:
str
,
np_value
:
np
.
array
,
summary_histogram
)
->
None
:
"""
Package the histogram summary.
...
...
@@ -347,7 +378,8 @@ def _fill_histogram_summary(tag: str, np_value: np.array, summary_histogram) ->
return
counts
,
edges
=
np
.
histogram
(
np_value
,
bins
=
'auto'
,
range
=
(
tensor_min
,
tensor_max
))
bin_number
=
_calc_histogram_bins
(
masked_value
.
count
())
counts
,
edges
=
np
.
histogram
(
np_value
,
bins
=
bin_number
,
range
=
(
tensor_min
,
tensor_max
))
for
ind
,
count
in
enumerate
(
counts
):
bucket
=
summary_histogram
.
buckets
.
add
()
...
...
tests/ut/python/train/summary/test_histogram_summary.py
浏览文件 @
62418143
...
...
@@ -22,6 +22,7 @@ import numpy as np
from
mindspore.common.tensor
import
Tensor
from
mindspore.train.summary.summary_record
import
SummaryRecord
,
_cache_summary_tensor_data
from
mindspore.train.summary._summary_adapter
import
_calc_histogram_bins
from
.summary_reader
import
SummaryReader
CUR_DIR
=
os
.
getcwd
()
...
...
@@ -139,7 +140,7 @@ def test_histogram_summary_same_value():
event
=
reader
.
read_event
()
LOG
.
debug
(
event
)
assert
len
(
event
.
summary
.
value
[
0
].
histogram
.
buckets
)
==
1
assert
len
(
event
.
summary
.
value
[
0
].
histogram
.
buckets
)
==
_calc_histogram_bins
(
dim1
*
dim2
)
def
test_histogram_summary_high_dims
():
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录