Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
3dfd1da1
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
3dfd1da1
编写于
2月 01, 2018
作者:
F
fengjiayi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Complete CreateBatchReaderOp
上级
1696cb0e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
61 addition
and
22 deletion
+61
-22
paddle/framework/reader.h
paddle/framework/reader.h
+6
-6
paddle/operators/create_reader_op.cc
paddle/operators/create_reader_op.cc
+55
-16
未找到文件。
paddle/framework/reader.h
浏览文件 @
3dfd1da1
...
...
@@ -44,9 +44,9 @@ class FileReader : public ReaderBase {
std
::
vector
<
DDim
>
shapes_
;
};
class
ReaderDecorato
r
:
public
ReaderBase
{
class
DecoratedReade
r
:
public
ReaderBase
{
public:
explicit
ReaderDecorato
r
(
ReaderBase
*
reader
)
:
reader_
(
reader
)
{
explicit
DecoratedReade
r
(
ReaderBase
*
reader
)
:
reader_
(
reader
)
{
PADDLE_ENFORCE_NOT_NULL
(
reader_
);
}
...
...
@@ -105,10 +105,10 @@ class RandomReader : public FileReader {
// decorators
class
ShuffleReader
:
public
ReaderDecorato
r
{
class
ShuffleReader
:
public
DecoratedReade
r
{
public:
ShuffleReader
(
ReaderBase
*
reader
,
int
buffer_size
)
:
ReaderDecorato
r
(
reader
),
buffer_size_
(
buffer_size
),
iteration_pos_
(
0
)
{
:
DecoratedReade
r
(
reader
),
buffer_size_
(
buffer_size
),
iteration_pos_
(
0
)
{
buffer_
.
reserve
(
buffer_size
);
}
...
...
@@ -120,10 +120,10 @@ class ShuffleReader : public ReaderDecorator {
size_t
iteration_pos_
;
};
class
BatchReader
:
public
ReaderDecorato
r
{
class
BatchReader
:
public
DecoratedReade
r
{
public:
BatchReader
(
ReaderBase
*
reader
,
int
batch_size
)
:
ReaderDecorato
r
(
reader
),
batch_size_
(
batch_size
)
{
:
DecoratedReade
r
(
reader
),
batch_size_
(
batch_size
)
{
buffer_
.
reserve
(
batch_size_
);
}
...
...
paddle/operators/create_reader_op.cc
浏览文件 @
3dfd1da1
...
...
@@ -19,11 +19,22 @@ namespace paddle {
namespace
operators
{
// general infershape for file readers
class
CreateReaderInferShape
:
public
framework
::
InferShapeBase
{
class
Create
File
ReaderInferShape
:
public
framework
::
InferShapeBase
{
public:
void
operator
()(
framework
::
InferShapeContext
*
ctx
)
const
override
{
PADDLE_ENFORCE
(
ctx
->
HasOutput
(
"Out"
),
"Output(Out) of CreateReaderOp should not be null."
);
"The output file reader should not be null."
);
}
};
// general infershape for decorated readers
class
CreateDecoratedReaderInferShape
:
public
framework
::
InferShapeBase
{
public:
void
operator
()(
framework
::
InferShapeContext
*
ctx
)
const
override
{
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"Underlying_reader"
),
"Input(Underlying_reader) should not be null."
);
PADDLE_ENFORCE
(
ctx
->
HasOutput
(
"Out"
),
"The output decorated reader should not be null."
);
}
};
...
...
@@ -83,17 +94,6 @@ class CreateRandomReaderOpMaker : public framework::OpProtoAndCheckerMaker {
}
};
class
CreateShuffleReaderInferShape
:
public
framework
::
InferShapeBase
{
public:
void
operator
()(
framework
::
InferShapeContext
*
ctx
)
const
override
{
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"Underlying_reader"
),
"Input(Underlying_reader) of CreateShuffleReaderOp should "
"not be null."
);
PADDLE_ENFORCE
(
ctx
->
HasOutput
(
"Out"
),
"Output(Out) of CreateShuffleReaderOp should not be null."
);
}
};
class
CreateShuffleReaderOp
:
public
framework
::
OperatorBase
{
public:
using
framework
::
OperatorBase
::
OperatorBase
;
...
...
@@ -121,7 +121,41 @@ class CreateShuffleReaderOpMaker : public framework::OpProtoAndCheckerMaker {
CreateShuffleReader Operator
A shuffle reader takes another reader as its 'underlying reader'
and output the underlying reader's outputs in a shuffled order.
and yields the underlying reader's outputs in a shuffled order.
)DOC"
);
}
};
class
CreateBatchReaderOp
:
public
framework
::
OperatorBase
{
public:
using
framework
::
OperatorBase
::
OperatorBase
;
void
Run
(
const
framework
::
Scope
&
scope
,
const
platform
::
Place
&
dev_place
)
const
override
{
const
auto
&
underlying_reader
=
scope
.
FindVar
(
Input
(
"Underlying_reader"
))
->
Get
<
framework
::
ReaderHolder
>
();
auto
*
out
=
scope
.
FindVar
(
Output
(
"Out"
))
->
template
GetMutable
<
framework
::
ReaderHolder
>();
out
->
Reset
(
new
framework
::
BatchReader
(
underlying_reader
.
Get
(),
Attr
<
int
>
(
"batch_size"
)));
}
};
class
CreateBatchReaderOpMaker
:
public
framework
::
OpProtoAndCheckerMaker
{
public:
CreateBatchReaderOpMaker
(
OpProto
*
op_proto
,
OpAttrChecker
*
op_checker
)
:
OpProtoAndCheckerMaker
(
op_proto
,
op_checker
)
{
AddInput
(
"Underlying_reader"
,
"(ReaderHolder) The underlying reader for creating a batch reader."
);
AddOutput
(
"Out"
,
"(ReaderHolder) The created batch reader."
);
AddAttr
<
int
>
(
"batch_size"
,
"How many instances the batch reader yields each time."
)
.
GreaterThan
(
0
);
AddComment
(
R"DOC(
CreateBatchReader Operator
A batch reader takes another reader as its 'underlying reader',
gathers the underlying reader's outputs and then yields them in batches.
)DOC"
);
}
};
...
...
@@ -131,9 +165,14 @@ class CreateShuffleReaderOpMaker : public framework::OpProtoAndCheckerMaker {
namespace
ops
=
paddle
::
operators
;
REGISTER_OPERATOR
(
create_random_reader
,
ops
::
CreateRandomReaderOp
<
float
>
,
ops
::
CreateReaderInferShape
,
ops
::
CreateRandomReaderOpMaker
,
ops
::
CreateFileReaderInferShape
,
ops
::
CreateRandomReaderOpMaker
,
paddle
::
framework
::
EmptyGradOpMaker
);
REGISTER_OPERATOR
(
create_shuffle_reader
,
ops
::
CreateShuffleReaderOp
,
ops
::
Create
Shuffle
ReaderInferShape
,
ops
::
Create
Decorated
ReaderInferShape
,
ops
::
CreateShuffleReaderOpMaker
,
paddle
::
framework
::
EmptyGradOpMaker
);
REGISTER_OPERATOR
(
create_batch_reader
,
ops
::
CreateBatchReaderOp
,
ops
::
CreateDecoratedReaderInferShape
,
ops
::
CreateBatchReaderOpMaker
,
paddle
::
framework
::
EmptyGradOpMaker
);
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录