Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
9774505e
M
mindspore
项目概览
magicwindyyd
/
mindspore
与 Fork 源项目一致
Fork自
MindSpore / mindspore
通知
1
Star
1
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看板
提交
9774505e
编写于
8月 10, 2020
作者:
A
anthonyaje
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixed dataset cpp api iterator build function
上级
9ad82f79
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
67 addition
and
8 deletion
+67
-8
mindspore/ccsrc/minddata/dataset/api/iterator.cc
mindspore/ccsrc/minddata/dataset/api/iterator.cc
+15
-8
tests/ut/cpp/dataset/c_api_dataset_ops_test.cc
tests/ut/cpp/dataset/c_api_dataset_ops_test.cc
+52
-0
未找到文件。
mindspore/ccsrc/minddata/dataset/api/iterator.cc
浏览文件 @
9774505e
...
...
@@ -61,13 +61,20 @@ Status Iterator::BuildAndLaunchTree(std::shared_ptr<Dataset> ds) {
RETURN_STATUS_UNEXPECTED
(
"Node operation returned nothing"
);
}
auto
root_op
=
root_ops
.
front
();
RETURN_UNEXPECTED_IF_NULL
(
root_op
);
RETURN_IF_NOT_OK
(
tree_
->
AssociateNode
(
root_op
));
q
.
push
(
std
::
make_pair
(
ds
,
root_op
));
// Iterate through all the DatasetOps returned by Dataset's Build(), associate them
// with the execution tree and add the child and parent relationship between the nodes
// Note that some Dataset objects might return more than one DatasetOps
// e.g. MapDataset will return [ProjectOp, MapOp] if project_columns is set for MapDataset
std
::
shared_ptr
<
DatasetOp
>
prev_op
=
nullptr
;
for
(
auto
op
:
root_ops
)
{
RETURN_IF_NOT_OK
(
tree_
->
AssociateNode
(
op
));
if
(
prev_op
!=
nullptr
)
{
RETURN_IF_NOT_OK
(
prev_op
->
AddChild
(
op
));
}
prev_op
=
op
;
}
// Add the last DatasetOp to the queue to be BFS.
q
.
push
(
std
::
make_pair
(
ds
,
root_ops
.
back
()));
// Traverse down to the children and convert them to the corresponding DatasetOps (i.e. execution tree nodes)
while
(
!
q
.
empty
())
{
...
...
@@ -94,7 +101,7 @@ Status Iterator::BuildAndLaunchTree(std::shared_ptr<Dataset> ds) {
q
.
push
(
std
::
make_pair
(
child
,
child_ops
.
back
()));
}
}
RETURN_IF_NOT_OK
(
tree_
->
AssignRoot
(
root_op
));
RETURN_IF_NOT_OK
(
tree_
->
AssignRoot
(
root_op
s
.
front
()
));
}
// Launch the execution tree.
...
...
tests/ut/cpp/dataset/c_api_dataset_ops_test.cc
浏览文件 @
9774505e
...
...
@@ -425,6 +425,58 @@ TEST_F(MindDataTestPipeline, TestProjectMap) {
iter
->
Stop
();
}
TEST_F
(
MindDataTestPipeline
,
TestProjectMapAutoInjection
)
{
MS_LOG
(
INFO
)
<<
"Doing MindDataTestPipeline.TestProjectMapAutoInjection"
;
// Create an ImageFolder Dataset
std
::
string
folder_path
=
datasets_root_path_
+
"/testPK/data/"
;
std
::
shared_ptr
<
Dataset
>
ds
=
ImageFolder
(
folder_path
,
true
,
RandomSampler
(
false
,
10
));
EXPECT_NE
(
ds
,
nullptr
);
// Create a Repeat operation on ds
int32_t
repeat_num
=
2
;
ds
=
ds
->
Repeat
(
repeat_num
);
EXPECT_NE
(
ds
,
nullptr
);
// Create objects for the tensor ops
std
::
shared_ptr
<
TensorOperation
>
resize_op
=
vision
::
Resize
({
30
,
30
});
EXPECT_NE
(
resize_op
,
nullptr
);
// Create a Map operation on ds
// {"image"} is the project columns. This will trigger auto injection of ProjectOp after MapOp.
ds
=
ds
->
Map
({
resize_op
},
{},
{},
{
"image"
});
EXPECT_NE
(
ds
,
nullptr
);
// Create an iterator over the result of the above dataset
// This will trigger the creation of the Execution Tree and launch it.
std
::
shared_ptr
<
Iterator
>
iter
=
ds
->
CreateIterator
();
EXPECT_NE
(
iter
,
nullptr
);
// Iterate the dataset and get each row
std
::
unordered_map
<
std
::
string
,
std
::
shared_ptr
<
Tensor
>>
row
;
iter
->
GetNextRow
(
&
row
);
// 'label' is dropped during the project op
EXPECT_EQ
(
row
.
find
(
"label"
),
row
.
end
());
// 'image' column should still exist
EXPECT_NE
(
row
.
find
(
"image"
),
row
.
end
());
uint64_t
i
=
0
;
while
(
row
.
size
()
!=
0
)
{
i
++
;
auto
image
=
row
[
"image"
];
MS_LOG
(
INFO
)
<<
"Tensor image shape: "
<<
image
->
shape
();
EXPECT_EQ
(
image
->
shape
()[
0
],
30
);
iter
->
GetNextRow
(
&
row
);
}
EXPECT_EQ
(
i
,
20
);
// Manually terminate the pipeline
iter
->
Stop
();
}
TEST_F
(
MindDataTestPipeline
,
TestZipSuccess
)
{
// Testing the member zip() function
MS_LOG
(
INFO
)
<<
"Doing MindDataTestPipeline-TestZipSuccess."
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录