Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qq_38905368
tensorflow
提交
b00e9404
T
tensorflow
项目概览
qq_38905368
/
tensorflow
与 Fork 源项目一致
从无法访问的项目Fork
通知
5
Star
0
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,发现更多精彩内容 >>
提交
b00e9404
编写于
11月 01, 2016
作者:
I
Illia Polosukhin
提交者:
TensorFlower Gardener
11月 01, 2016
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixes #4226: Allow to specify partial shape in sparse_placeholder.
Change: 137854718
上级
6172351b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
46 addition
and
7 deletion
+46
-7
tensorflow/python/client/session_test.py
tensorflow/python/client/session_test.py
+31
-1
tensorflow/python/ops/array_ops.py
tensorflow/python/ops/array_ops.py
+15
-6
未找到文件。
tensorflow/python/client/session_test.py
浏览文件 @
b00e9404
...
...
@@ -599,7 +599,37 @@ class SessionTest(test_util.TensorFlowTestCase):
self
.
assertAllEqual
(
sp2_out
.
values
,
values
)
self
.
assertAllEqual
(
sp2_out
.
shape
,
shape
)
def
testFeedSparePlaceholderConstantShape
(
self
):
def
testFeedSparsePlaceholderPartialShape
(
self
):
with
session
.
Session
()
as
s
:
indices
=
np
.
array
([[
3
,
2
,
0
],
[
4
,
5
,
1
]]).
astype
(
np
.
int64
)
values
=
np
.
array
([
1.0
,
2.0
]).
astype
(
np
.
float32
)
shape
=
np
.
array
([
7
,
9
,
2
]).
astype
(
np
.
int64
)
sp
=
array_ops
.
sparse_placeholder
(
shape
=
[
None
,
9
,
2
],
dtype
=
np
.
float32
,
name
=
'placeholder1'
)
sp_indices
=
array_ops
.
identity
(
sp
.
indices
)
sp_values
=
array_ops
.
identity
(
sp
.
values
)
sp_shape
=
array_ops
.
identity
(
sp
.
shape
)
sp2
=
ops
.
SparseTensor
(
sp_indices
,
sp_values
,
sp_shape
)
# Feed with tuple
indices_out
,
values_out
,
shape_out
=
s
.
run
(
[
sp_indices
,
sp_values
,
sp_shape
],
{
sp
:
(
indices
,
values
,
shape
)})
self
.
assertAllEqual
(
indices_out
,
indices
)
self
.
assertAllEqual
(
values_out
,
values
)
self
.
assertAllEqual
(
shape_out
,
shape
)
# Feed with SparseTensorValue
indices_out
,
values_out
,
shape_out
=
s
.
run
(
[
sp_indices
,
sp_values
,
sp_shape
],
{
sp
:
ops
.
SparseTensorValue
(
indices
,
values
,
shape
)})
self
.
assertAllEqual
(
indices_out
,
indices
)
self
.
assertAllEqual
(
values_out
,
values
)
self
.
assertAllEqual
(
shape_out
,
shape
)
# Feed with SparseTensorValue, fetch SparseTensorValue
sp2_out
=
s
.
run
(
sp2
,
{
sp
:
ops
.
SparseTensorValue
(
indices
,
values
,
shape
)})
self
.
assertAllEqual
(
sp2_out
.
indices
,
indices
)
self
.
assertAllEqual
(
sp2_out
.
values
,
values
)
self
.
assertAllEqual
(
sp2_out
.
shape
,
shape
)
def
testFeedSparsePlaceholderConstantShape
(
self
):
with
session
.
Session
()
as
s
:
indices
=
np
.
array
([[
3
,
2
,
0
],
[
4
,
5
,
1
]]).
astype
(
np
.
int64
)
values
=
np
.
array
([
1.0
,
2.0
]).
astype
(
np
.
float32
)
...
...
tensorflow/python/ops/array_ops.py
浏览文件 @
b00e9404
...
...
@@ -1445,6 +1445,17 @@ def placeholder(dtype, shape=None, name=None):
return
ret
# pylint: disable=redefined-outer-name
def
_normalize_sparse_shape
(
shape
,
name
):
"""Takes numpy array or Tensor or None and returns either None or Tensor."""
if
shape
is
None
:
return
None
if
not
isinstance
(
shape
,
ops
.
Tensor
):
for
el
in
shape
:
if
el
is
None
:
return
None
return
ops
.
convert_to_tensor
(
shape
,
name
=
name
)
def
sparse_placeholder
(
dtype
,
shape
=
None
,
name
=
None
):
"""Inserts a placeholder for a sparse tensor that will be always fed.
...
...
@@ -1484,13 +1495,10 @@ def sparse_placeholder(dtype, shape=None, name=None):
A `SparseTensor` that may be used as a handle for feeding a value, but not
evaluated directly.
"""
shape_name
=
(
name
+
"/shape"
)
if
name
is
not
None
else
None
shape
=
_normalize_sparse_shape
(
shape
,
shape_name
)
if
shape
is
None
:
shape
=
placeholder
(
dtypes
.
int64
,
shape
=
[
None
],
name
=
(
name
+
"/shape"
)
if
name
is
not
None
else
None
)
else
:
shape
=
ops
.
convert_to_tensor
(
shape
,
name
=
(
name
+
"/shape"
)
if
name
is
not
None
else
None
)
shape
=
placeholder
(
dtypes
.
int64
,
shape
=
[
None
],
name
=
shape_name
)
return
ops
.
SparseTensor
(
values
=
placeholder
(
dtype
,
shape
=
[
None
],
...
...
@@ -1500,6 +1508,7 @@ def sparse_placeholder(dtype, shape=None, name=None):
name
=
(
name
+
"/indices"
)
if
name
is
not
None
else
None
),
shape
=
shape
)
# pylint: enable=redefined-outer-name
def
pad
(
tensor
,
paddings
,
mode
=
"CONSTANT"
,
name
=
None
):
# pylint: disable=invalid-name
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录