Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
tensorflow
提交
11b33344
T
tensorflow
项目概览
xxadev
/
tensorflow
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
tensorflow
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
11b33344
编写于
7月 17, 2019
作者:
T
TensorFlower Gardener
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #30053 from yongtang:30040-BinaryCrossEntropy
PiperOrigin-RevId: 258598105
上级
ca146efb
34d03e4e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
15 addition
and
2 deletion
+15
-2
tensorflow/python/keras/backend.py
tensorflow/python/keras/backend.py
+1
-0
tensorflow/python/keras/distribute/distribute_strategy_test.py
...rflow/python/keras/distribute/distribute_strategy_test.py
+2
-2
tensorflow/python/keras/losses_test.py
tensorflow/python/keras/losses_test.py
+12
-0
未找到文件。
tensorflow/python/keras/backend.py
浏览文件 @
11b33344
...
...
@@ -4328,6 +4328,7 @@ def binary_crossentropy(target, output, from_logits=False):
if
not
from_logits
:
if
(
isinstance
(
output
,
(
ops
.
EagerTensor
,
variables_module
.
Variable
))
or
output
.
op
.
type
!=
'Sigmoid'
):
target
.
get_shape
().
assert_is_compatible_with
(
output
.
get_shape
())
epsilon_
=
_constant_to_tensor
(
epsilon
(),
output
.
dtype
.
base_dtype
)
output
=
clip_ops
.
clip_by_value
(
output
,
epsilon_
,
1.
-
epsilon_
)
...
...
tensorflow/python/keras/distribute/distribute_strategy_test.py
浏览文件 @
11b33344
...
...
@@ -846,7 +846,7 @@ class TestDistributionStrategyWithDatasets(test.TestCase,
with
self
.
cached_session
():
with
distribution
.
scope
():
input_img
=
keras
.
layers
.
Input
([
64
,
64
,
3
],
name
=
'img'
)
input_lbl
=
keras
.
layers
.
Input
([
64
,
64
,
1
],
name
=
'lbl'
)
input_lbl
=
keras
.
layers
.
Input
([
64
,
64
,
2
],
name
=
'lbl'
)
input_weight
=
keras
.
layers
.
Input
([
64
,
64
],
name
=
'weight'
)
predict
=
keras
.
layers
.
Conv2D
(
2
,
[
1
,
1
],
padding
=
'same'
)(
input_img
)
loss_lambda
=
keras
.
layers
.
Lambda
(
...
...
@@ -864,7 +864,7 @@ class TestDistributionStrategyWithDatasets(test.TestCase,
return
inputs
,
targets
fake_imgs
=
np
.
ones
([
50
,
64
,
64
,
3
],
dtype
=
np
.
float32
)
fake_lbls
=
np
.
ones
([
50
,
64
,
64
,
1
],
dtype
=
np
.
float32
)
fake_lbls
=
np
.
ones
([
50
,
64
,
64
,
2
],
dtype
=
np
.
float32
)
fake_weights
=
np
.
ones
([
50
,
64
,
64
],
dtype
=
np
.
float32
)
data
=
dataset_ops
.
Dataset
.
from_tensor_slices
(
...
...
tensorflow/python/keras/losses_test.py
浏览文件 @
11b33344
...
...
@@ -825,6 +825,18 @@ class BinaryCrossentropyTest(test.TestCase):
expected_value
=
(
100.0
+
50.0
*
label_smoothing
)
/
3.0
self
.
assertAlmostEqual
(
self
.
evaluate
(
loss
),
expected_value
,
3
)
def
test_shape_mismatch
(
self
):
y_true
=
np
.
array
([[
1.
],
[
1.
],
[
1.
],
[
0.
],
[
1.
],
[
0.
],
[
0.
],
[
1.
],
[
1.
],
[
0.
]]).
astype
(
np
.
float32
)
y_pred
=
np
.
array
([[
0.
],
[
0.
],
[
0.
],
[
1.
],
[
1.
],
[
0.
],
[
0.
],
[
1.
],
[
0.
],
[
1.
]]).
astype
(
np
.
float32
)
bce_obj
=
keras
.
losses
.
BinaryCrossentropy
()
loss
=
bce_obj
(
y_true
,
y_pred
)
self
.
assertAlmostEqual
(
self
.
evaluate
(
loss
),
9.23662
,
3
)
with
self
.
assertRaisesRegexp
(
ValueError
,
'Shapes .+ are incompatible'
):
loss
=
bce_obj
(
np
.
squeeze
(
y_true
),
y_pred
)
@
test_util
.
run_all_in_graph_and_eager_modes
class
CategoricalCrossentropyTest
(
test
.
TestCase
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录