Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
e9422646
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看板
提交
e9422646
编写于
8月 06, 2020
作者:
M
mindspore-ci-bot
提交者:
Gitee
8月 06, 2020
浏览文件
操作
浏览文件
下载
差异文件
!4023 change sampler parameter to support std::move
Merge pull request !4023 from 章一智/cpp_api_sampler
上级
6aa65da5
c65670b1
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
25 addition
and
18 deletion
+25
-18
mindspore/ccsrc/minddata/dataset/api/samplers.cc
mindspore/ccsrc/minddata/dataset/api/samplers.cc
+8
-9
mindspore/ccsrc/minddata/dataset/include/samplers.h
mindspore/ccsrc/minddata/dataset/include/samplers.h
+7
-9
tests/ut/cpp/dataset/c_api_test.cc
tests/ut/cpp/dataset/c_api_test.cc
+10
-0
未找到文件。
mindspore/ccsrc/minddata/dataset/api/samplers.cc
浏览文件 @
e9422646
...
...
@@ -71,8 +71,8 @@ std::shared_ptr<SequentialSamplerObj> SequentialSampler(int64_t start_index, int
}
/// Function to create a Subset Random Sampler.
std
::
shared_ptr
<
SubsetRandomSamplerObj
>
SubsetRandomSampler
(
const
std
::
vector
<
int64_t
>
&
indices
,
int64_t
num_samples
)
{
auto
sampler
=
std
::
make_shared
<
SubsetRandomSamplerObj
>
(
indices
,
num_samples
);
std
::
shared_ptr
<
SubsetRandomSamplerObj
>
SubsetRandomSampler
(
std
::
vector
<
int64_t
>
indices
,
int64_t
num_samples
)
{
auto
sampler
=
std
::
make_shared
<
SubsetRandomSamplerObj
>
(
std
::
move
(
indices
)
,
num_samples
);
// Input validation
if
(
!
sampler
->
ValidateParams
())
{
return
nullptr
;
...
...
@@ -81,9 +81,9 @@ std::shared_ptr<SubsetRandomSamplerObj> SubsetRandomSampler(const std::vector<in
}
/// Function to create a Weighted Random Sampler.
std
::
shared_ptr
<
WeightedRandomSamplerObj
>
WeightedRandomSampler
(
const
std
::
vector
<
double
>
&
weights
,
int64_t
num_samples
,
std
::
shared_ptr
<
WeightedRandomSamplerObj
>
WeightedRandomSampler
(
std
::
vector
<
double
>
weights
,
int64_t
num_samples
,
bool
replacement
)
{
auto
sampler
=
std
::
make_shared
<
WeightedRandomSamplerObj
>
(
weights
,
num_samples
,
replacement
);
auto
sampler
=
std
::
make_shared
<
WeightedRandomSamplerObj
>
(
std
::
move
(
weights
)
,
num_samples
,
replacement
);
// Input validation
if
(
!
sampler
->
ValidateParams
())
{
return
nullptr
;
...
...
@@ -190,8 +190,8 @@ std::shared_ptr<Sampler> SequentialSamplerObj::Build() {
}
// SubsetRandomSampler
SubsetRandomSamplerObj
::
SubsetRandomSamplerObj
(
const
std
::
vector
<
int64_t
>
&
indices
,
int64_t
num_samples
)
:
indices_
(
indices
),
num_samples_
(
num_samples
)
{}
SubsetRandomSamplerObj
::
SubsetRandomSamplerObj
(
std
::
vector
<
int64_t
>
indices
,
int64_t
num_samples
)
:
indices_
(
std
::
move
(
indices
)
),
num_samples_
(
num_samples
)
{}
bool
SubsetRandomSamplerObj
::
ValidateParams
()
{
if
(
num_samples_
<
0
)
{
...
...
@@ -208,9 +208,8 @@ std::shared_ptr<Sampler> SubsetRandomSamplerObj::Build() {
}
// WeightedRandomSampler
WeightedRandomSamplerObj
::
WeightedRandomSamplerObj
(
const
std
::
vector
<
double
>
&
weights
,
int64_t
num_samples
,
bool
replacement
)
:
weights_
(
weights
),
num_samples_
(
num_samples
),
replacement_
(
replacement
)
{}
WeightedRandomSamplerObj
::
WeightedRandomSamplerObj
(
std
::
vector
<
double
>
weights
,
int64_t
num_samples
,
bool
replacement
)
:
weights_
(
std
::
move
(
weights
)),
num_samples_
(
num_samples
),
replacement_
(
replacement
)
{}
bool
WeightedRandomSamplerObj
::
ValidateParams
()
{
if
(
num_samples_
<
0
)
{
...
...
mindspore/ccsrc/minddata/dataset/include/samplers.h
浏览文件 @
e9422646
...
...
@@ -87,8 +87,7 @@ std::shared_ptr<SequentialSamplerObj> SequentialSampler(int64_t start_index = 0,
/// \param[in] indices - A vector sequence of indices.
/// \param[in] num_samples - The number of samples to draw (default to all elements).
/// \return Shared pointer to the current Sampler.
std
::
shared_ptr
<
SubsetRandomSamplerObj
>
SubsetRandomSampler
(
const
std
::
vector
<
int64_t
>
&
indices
,
int64_t
num_samples
=
0
);
std
::
shared_ptr
<
SubsetRandomSamplerObj
>
SubsetRandomSampler
(
std
::
vector
<
int64_t
>
indices
,
int64_t
num_samples
=
0
);
/// Function to create a Weighted Random Sampler.
/// \notes Samples the elements from [0, len(weights) - 1] randomly with the given
...
...
@@ -97,8 +96,8 @@ std::shared_ptr<SubsetRandomSamplerObj> SubsetRandomSampler(const std::vector<in
/// \param[in] num_samples - The number of samples to draw (default to all elements).
/// \param[in] replacement - If True, put the sample ID back for the next draw.
/// \return Shared pointer to the current Sampler.
std
::
shared_ptr
<
WeightedRandomSamplerObj
>
WeightedRandomSampler
(
const
std
::
vector
<
double
>
&
weights
,
int64_t
num_samples
=
0
,
bool
replacement
=
true
);
std
::
shared_ptr
<
WeightedRandomSamplerObj
>
WeightedRandomSampler
(
std
::
vector
<
double
>
weights
,
int64_t
num_samples
=
0
,
bool
replacement
=
true
);
/* ####################################### Derived Sampler classes ################################# */
class
DistributedSamplerObj
:
public
SamplerObj
{
...
...
@@ -169,7 +168,7 @@ class SequentialSamplerObj : public SamplerObj {
class
SubsetRandomSamplerObj
:
public
SamplerObj
{
public:
SubsetRandomSamplerObj
(
const
std
::
vector
<
int64_t
>
&
indices
,
int64_t
num_samples
);
SubsetRandomSamplerObj
(
std
::
vector
<
int64_t
>
indices
,
int64_t
num_samples
);
~
SubsetRandomSamplerObj
()
=
default
;
...
...
@@ -178,14 +177,13 @@ class SubsetRandomSamplerObj : public SamplerObj {
bool
ValidateParams
()
override
;
private:
const
std
::
vector
<
int64_t
>
&
indices_
;
const
std
::
vector
<
int64_t
>
indices_
;
int64_t
num_samples_
;
};
class
WeightedRandomSamplerObj
:
public
SamplerObj
{
public:
explicit
WeightedRandomSamplerObj
(
const
std
::
vector
<
double
>
&
weights
,
int64_t
num_samples
=
0
,
bool
replacement
=
true
);
explicit
WeightedRandomSamplerObj
(
std
::
vector
<
double
>
weights
,
int64_t
num_samples
=
0
,
bool
replacement
=
true
);
~
WeightedRandomSamplerObj
()
=
default
;
...
...
@@ -194,7 +192,7 @@ class WeightedRandomSamplerObj : public SamplerObj {
bool
ValidateParams
()
override
;
private:
const
std
::
vector
<
double
>
&
weights_
;
const
std
::
vector
<
double
>
weights_
;
int64_t
num_samples_
;
bool
replacement_
;
};
...
...
tests/ut/cpp/dataset/c_api_test.cc
浏览文件 @
e9422646
...
...
@@ -369,6 +369,16 @@ TEST_F(MindDataTestPipeline, TestImageFolderWithSamplers) {
iter
->
Stop
();
}
TEST_F
(
MindDataTestPipeline
,
TestSamplersMoveParameters
)
{
std
::
vector
<
int64_t
>
indices
=
{
1
,
3
,
5
,
7
,
9
,
11
,
13
,
15
,
17
,
19
,
21
,
23
};
std
::
shared_ptr
<
SamplerObj
>
sampl1
=
SubsetRandomSampler
(
indices
);
EXPECT_FALSE
(
indices
.
empty
());
EXPECT_NE
(
sampl1
->
Build
(),
nullptr
);
std
::
shared_ptr
<
SamplerObj
>
sampl2
=
SubsetRandomSampler
(
std
::
move
(
indices
));
EXPECT_TRUE
(
indices
.
empty
());
EXPECT_NE
(
sampl2
->
Build
(),
nullptr
);
}
TEST_F
(
MindDataTestPipeline
,
TestPad
)
{
MS_LOG
(
INFO
)
<<
"Doing MindDataTestPipeline-TestPad."
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录