Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
tensorflow
提交
c092f31c
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,发现更多精彩内容 >>
提交
c092f31c
编写于
3月 16, 2017
作者:
A
A. Unique TensorFlower
提交者:
TensorFlower Gardener
3月 16, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Tensorflow] Expose API to lookup TensorSlice.
Change: 150384503
上级
433c8c89
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
34 addition
and
5 deletion
+34
-5
tensorflow/core/util/tensor_bundle/tensor_bundle.cc
tensorflow/core/util/tensor_bundle/tensor_bundle.cc
+12
-0
tensorflow/core/util/tensor_bundle/tensor_bundle.h
tensorflow/core/util/tensor_bundle/tensor_bundle.h
+6
-0
tensorflow/core/util/tensor_bundle/tensor_bundle_test.cc
tensorflow/core/util/tensor_bundle/tensor_bundle_test.cc
+16
-5
未找到文件。
tensorflow/core/util/tensor_bundle/tensor_bundle.cc
浏览文件 @
c092f31c
...
...
@@ -712,6 +712,18 @@ Status BundleReader::Lookup(StringPiece key, Tensor* val) {
}
}
Status
BundleReader
::
LookupTensorSlices
(
StringPiece
key
,
std
::
vector
<
TensorSlice
>*
slices
)
{
slices
->
clear
();
BundleEntryProto
entry
;
TF_RETURN_IF_ERROR
(
GetBundleEntryProto
(
key
,
&
entry
));
slices
->
reserve
(
entry
.
slices_size
());
for
(
const
auto
&
slice
:
entry
.
slices
())
{
slices
->
emplace_back
(
slice
);
}
return
Status
::
OK
();
}
Status
BundleReader
::
LookupSlice
(
StringPiece
full_tensor_key
,
const
TensorSlice
&
slice_spec
,
Tensor
*
val
)
{
BundleEntryProto
entry
;
...
...
tensorflow/core/util/tensor_bundle/tensor_bundle.h
浏览文件 @
c092f31c
...
...
@@ -207,6 +207,12 @@ class BundleReader {
// REQUIRES: status().ok()
Status
Lookup
(
StringPiece
key
,
Tensor
*
val
)
TF_MUST_USE_RESULT
;
// Looks up the slices of the tensor keyed by "key". On OK, "slices"
// is non-empty if and only if the tensor is a partitioned tensor.
// REQUIRES: status().ok()
Status
LookupTensorSlices
(
StringPiece
key
,
std
::
vector
<
TensorSlice
>*
slices
)
TF_MUST_USE_RESULT
;
// Looks up a specific slice of a partitioned tensor.
// It is only required that the stored slices cover the requested slice,
// namely "slice_spec" is a subset of the union of the stored slices.
...
...
tensorflow/core/util/tensor_bundle/tensor_bundle_test.cc
浏览文件 @
c092f31c
...
...
@@ -245,15 +245,14 @@ TEST(TensorBundleTest, PartitionedVariables) {
// Adds two slices.
// First slice: column 0, all zeros.
// Second slice: column 1 to rest, all ones.
TensorSlice
slice1
=
TensorSlice
::
ParseOrDie
(
"-:0,1"
);
TensorSlice
slice2
=
TensorSlice
::
ParseOrDie
(
"-:1,9"
);
{
BundleWriter
writer
(
Env
::
Default
(),
Prefix
(
"foo"
));
TensorSlice
slice
=
TensorSlice
::
ParseOrDie
(
"-:0,1"
);
TF_ASSERT_OK
(
writer
.
AddSlice
(
"foo"
,
kFullShape
,
TensorSlice
::
ParseOrDie
(
"-:0,1"
),
TF_ASSERT_OK
(
writer
.
AddSlice
(
"foo"
,
kFullShape
,
slice1
,
Constant
<
float
>
(
0.
,
TensorShape
({
5
,
1
}))));
TF_ASSERT_OK
(
writer
.
AddSlice
(
"foo"
,
kFullShape
,
TensorSlice
::
ParseOrDie
(
"-:1,9"
),
TF_ASSERT_OK
(
writer
.
AddSlice
(
"foo"
,
kFullShape
,
slice2
,
Constant
<
float
>
(
1.
,
TensorShape
({
5
,
9
}))));
TF_ASSERT_OK
(
writer
.
Finish
());
}
...
...
@@ -274,6 +273,18 @@ TEST(TensorBundleTest, PartitionedVariables) {
TF_ASSERT_OK
(
reader
.
Lookup
(
"foo"
,
&
val
));
test
::
ExpectTensorEqual
<
float
>
(
val
,
expected_val
);
}
// Reads all slices.
{
BundleReader
reader
(
Env
::
Default
(),
Prefix
(
"foo"
));
TF_ASSERT_OK
(
reader
.
status
());
std
::
vector
<
TensorSlice
>
slices
;
TF_ASSERT_OK
(
reader
.
LookupTensorSlices
(
"foo"
,
&
slices
));
EXPECT_EQ
(
2
,
slices
.
size
());
EXPECT_EQ
(
slice1
.
DebugString
(),
slices
[
0
].
DebugString
());
EXPECT_EQ
(
slice2
.
DebugString
(),
slices
[
1
].
DebugString
());
}
// Reads a slice consisting of first two columns, "cutting" both slices.
{
BundleReader
reader
(
Env
::
Default
(),
Prefix
(
"foo"
));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录