Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
tensorflow
提交
7160a7e0
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,发现更多精彩内容 >>
提交
7160a7e0
编写于
3月 13, 2017
作者:
N
Nathan Silberman
提交者:
TensorFlower Gardener
3月 13, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Adding test for associative property of pairwise squared loss.
Change: 149955752
上级
c1af2f81
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
82 addition
and
5 deletion
+82
-5
tensorflow/contrib/losses/python/losses/loss_ops_test.py
tensorflow/contrib/losses/python/losses/loss_ops_test.py
+46
-5
tensorflow/python/kernel_tests/losses_test.py
tensorflow/python/kernel_tests/losses_test.py
+36
-0
未找到文件。
tensorflow/contrib/losses/python/losses/loss_ops_test.py
浏览文件 @
7160a7e0
...
...
@@ -30,6 +30,7 @@ from tensorflow.python.framework import random_seed
from
tensorflow.python.ops
import
array_ops
from
tensorflow.python.ops
import
init_ops
from
tensorflow.python.ops
import
math_ops
from
tensorflow.python.ops
import
random_ops
from
tensorflow.python.ops
import
variable_scope
from
tensorflow.python.ops
import
variables
from
tensorflow.python.platform
import
test
...
...
@@ -265,7 +266,8 @@ class SoftmaxCrossEntropyLossTest(test.TestCase):
[
1
,
0
,
0
],
[
0
,
1
,
0
]])
weights
=
[[
2.3
],
[
2.4
],
[
2.5
]]
weights_placeholder
=
array_ops
.
placeholder
(
dtypes
.
float32
,
shape
=
[
None
,
None
])
weights_placeholder
=
array_ops
.
placeholder
(
dtypes
.
float32
,
shape
=
[
None
,
None
])
loss
=
loss_ops
.
softmax_cross_entropy
(
logits
,
labels
,
weights_placeholder
)
with
self
.
test_session
()
as
sess
:
loss
=
sess
.
run
(
loss
,
{
weights_placeholder
:
weights
})
...
...
@@ -479,8 +481,10 @@ class SparseSoftmaxCrossEntropyLossTest(test.TestCase):
[
0.0
,
0.0
,
10.0
]])
labels
=
constant_op
.
constant
([
2
,
0
,
1
])
weights
=
[
2.3
,
2.4
,
2.5
]
weights_placeholder
=
array_ops
.
placeholder
(
dtypes
.
float32
,
shape
=
[
None
])
loss
=
loss_ops
.
sparse_softmax_cross_entropy
(
logits
,
labels
,
weights_placeholder
)
weights_placeholder
=
array_ops
.
placeholder
(
dtypes
.
float32
,
shape
=
[
None
])
loss
=
loss_ops
.
sparse_softmax_cross_entropy
(
logits
,
labels
,
weights_placeholder
)
with
self
.
test_session
()
as
sess
:
loss
=
sess
.
run
(
loss
,
{
weights_placeholder
:
weights
})
self
.
assertAlmostEqual
(
np
.
average
(
weights
)
*
10.0
,
loss
,
3
)
...
...
@@ -491,8 +495,10 @@ class SparseSoftmaxCrossEntropyLossTest(test.TestCase):
[
0.0
,
0.0
,
10.0
]])
labels
=
constant_op
.
constant
([
2
,
0
,
1
])
weights
=
[[
2.3
],
[
2.4
],
[
2.5
]]
weights_placeholder
=
array_ops
.
placeholder
(
dtypes
.
float32
,
shape
=
[
None
,
None
])
loss
=
loss_ops
.
sparse_softmax_cross_entropy
(
logits
,
labels
,
weights_placeholder
)
weights_placeholder
=
array_ops
.
placeholder
(
dtypes
.
float32
,
shape
=
[
None
,
None
])
loss
=
loss_ops
.
sparse_softmax_cross_entropy
(
logits
,
labels
,
weights_placeholder
)
with
self
.
test_session
()
as
sess
:
loss
=
sess
.
run
(
loss
,
{
weights_placeholder
:
weights
})
self
.
assertAlmostEqual
(
np
.
average
(
weights
)
*
10.0
,
loss
,
3
)
...
...
@@ -1054,6 +1060,41 @@ class MeanPairwiseSquaresErrorTest(test.TestCase):
with
self
.
test_session
():
self
.
assertAlmostEqual
(
0.0
,
loss
.
eval
(),
3
)
def
testLossIsAssociativeAcrossBatchElements
(
self
):
with
ops
.
Graph
().
as_default
():
random_seed
.
set_random_seed
(
0
)
height
=
3
width
=
4
shape
=
(
1
,
height
,
width
,
1
)
labels0
=
random_ops
.
random_uniform
(
shape
,
minval
=
0
,
maxval
=
1
,
dtype
=
dtypes
.
float32
)
predictions0
=
random_ops
.
random_uniform
(
shape
,
minval
=
0
,
maxval
=
1
,
dtype
=
dtypes
.
float32
)
labels1
=
random_ops
.
random_uniform
(
shape
,
minval
=
0
,
maxval
=
1
,
dtype
=
dtypes
.
float32
)
predictions1
=
random_ops
.
random_uniform
(
shape
,
minval
=
0
,
maxval
=
1
,
dtype
=
dtypes
.
float32
)
loss0
=
loss_ops
.
mean_pairwise_squared_error
(
predictions
=
predictions0
,
labels
=
labels0
)
loss1
=
loss_ops
.
mean_pairwise_squared_error
(
predictions
=
predictions1
,
labels
=
labels1
)
loss0_1
=
loss_ops
.
mean_pairwise_squared_error
(
predictions
=
array_ops
.
concat
([
predictions0
,
predictions1
],
0
),
labels
=
array_ops
.
concat
([
labels0
,
labels1
],
0
))
with
self
.
test_session
()
as
session
:
loss0
,
loss1
,
loss0_1
=
session
.
run
([
loss0
,
loss1
,
loss0_1
])
self
.
assertTrue
(
loss0
>
0
)
self
.
assertTrue
(
loss1
>
0
)
self
.
assertAlmostEqual
(
loss0
+
loss1
,
loss0_1
,
5
)
class
CosineDistanceLossTest
(
test
.
TestCase
):
...
...
tensorflow/python/kernel_tests/losses_test.py
浏览文件 @
7160a7e0
...
...
@@ -28,6 +28,7 @@ from tensorflow.python.framework import random_seed
from
tensorflow.python.ops
import
array_ops
from
tensorflow.python.ops
import
init_ops
from
tensorflow.python.ops
import
math_ops
from
tensorflow.python.ops
import
random_ops
from
tensorflow.python.ops
import
variable_scope
from
tensorflow.python.ops
import
variables
from
tensorflow.python.ops.losses
import
losses
...
...
@@ -1015,6 +1016,41 @@ class MeanPairwiseSquaredErrorTest(test.TestCase):
self
.
_labels
,
self
.
_predictions
,
expected_loss
=
0.0
,
weights
=
np
.
zeros
((
2
,
1
)))
def
testLossIsAssociativeAcrossBatchElements
(
self
):
with
ops
.
Graph
().
as_default
():
random_seed
.
set_random_seed
(
0
)
height
=
3
width
=
4
shape
=
(
1
,
height
,
width
,
1
)
labels0
=
random_ops
.
random_uniform
(
shape
,
minval
=
0
,
maxval
=
1
,
dtype
=
dtypes
.
float32
)
predictions0
=
random_ops
.
random_uniform
(
shape
,
minval
=
0
,
maxval
=
1
,
dtype
=
dtypes
.
float32
)
labels1
=
random_ops
.
random_uniform
(
shape
,
minval
=
0
,
maxval
=
1
,
dtype
=
dtypes
.
float32
)
predictions1
=
random_ops
.
random_uniform
(
shape
,
minval
=
0
,
maxval
=
1
,
dtype
=
dtypes
.
float32
)
loss0
=
losses
.
mean_pairwise_squared_error
(
labels
=
labels0
,
predictions
=
predictions0
)
loss1
=
losses
.
mean_pairwise_squared_error
(
labels
=
labels1
,
predictions
=
predictions1
)
loss0_1
=
losses
.
mean_pairwise_squared_error
(
labels
=
array_ops
.
concat
([
labels0
,
labels1
],
0
),
predictions
=
array_ops
.
concat
([
predictions0
,
predictions1
],
0
))
with
self
.
test_session
()
as
session
:
loss0
,
loss1
,
loss0_1
=
session
.
run
([
loss0
,
loss1
,
loss0_1
])
self
.
assertTrue
(
loss0
>
0
)
self
.
assertTrue
(
loss1
>
0
)
self
.
assertAlmostEqual
(
loss0
+
loss1
,
loss0_1
,
5
)
class
CosineDistanceLossTest
(
test
.
TestCase
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录