Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
d8cc21da
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看板
提交
d8cc21da
编写于
2月 01, 2018
作者:
F
fengjiayi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refine inheritance relationship
上级
f32ca636
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
37 addition
and
31 deletion
+37
-31
paddle/framework/reader.cc
paddle/framework/reader.cc
+1
-1
paddle/framework/reader.h
paddle/framework/reader.h
+36
-30
未找到文件。
paddle/framework/reader.cc
浏览文件 @
d8cc21da
...
@@ -17,7 +17,7 @@
...
@@ -17,7 +17,7 @@
namespace
paddle
{
namespace
paddle
{
namespace
framework
{
namespace
framework
{
DDim
Reader
::
shape
(
size_t
idx
)
const
{
DDim
File
Reader
::
shape
(
size_t
idx
)
const
{
PADDLE_ENFORCE_LT
(
PADDLE_ENFORCE_LT
(
idx
,
shapes_
.
size
(),
idx
,
shapes_
.
size
(),
"Cannot get the %d'th shape, 'shapes_' only has %d elements."
,
idx
,
"Cannot get the %d'th shape, 'shapes_' only has %d elements."
,
idx
,
...
...
paddle/framework/reader.h
浏览文件 @
d8cc21da
...
@@ -20,32 +20,48 @@
...
@@ -20,32 +20,48 @@
namespace
paddle
{
namespace
paddle
{
namespace
framework
{
namespace
framework
{
class
Reader
{
class
Reader
Base
{
public:
public:
Reader
()
{}
explicit
Reader
(
const
std
::
vector
<
DDim
>&
shapes
)
:
shapes_
(
shapes
)
{}
virtual
std
::
vector
<
LoDTensor
>
ReadNext
()
=
0
;
virtual
std
::
vector
<
LoDTensor
>
ReadNext
()
=
0
;
virtual
bool
HasNext
()
const
=
0
;
virtual
bool
HasNext
()
const
=
0
;
virtual
DDim
shape
(
size_t
idx
)
const
;
virtual
DDim
shape
(
size_t
idx
)
const
=
0
;
virtual
std
::
vector
<
DDim
>
shapes
()
const
{
return
shapes_
;
}
virtual
std
::
vector
<
DDim
>
shapes
()
const
=
0
;
virtual
~
Reader
()
{}
virtual
~
ReaderBase
()
{}
};
private:
class
FileReader
:
public
ReaderBase
{
// set private to prevent directly access in decorators
public:
// a decorator should access its underlying reader_'s shape, not its own.
explicit
FileReader
(
const
std
::
vector
<
DDim
>&
shapes
)
:
shapes_
(
shapes
)
{}
DDim
shape
(
size_t
idx
)
const
override
;
std
::
vector
<
DDim
>
shapes
()
const
override
{
return
shapes_
;
}
protected:
std
::
vector
<
DDim
>
shapes_
;
std
::
vector
<
DDim
>
shapes_
;
};
};
class
ReaderDecorator
:
public
ReaderBase
{
public:
explicit
ReaderDecorator
(
ReaderBase
*
reader
)
:
reader_
(
reader
)
{}
bool
HasNext
()
const
override
{
return
reader_
->
HasNext
();
}
DDim
shape
(
size_t
idx
)
const
override
{
return
reader_
->
shape
(
idx
);
}
std
::
vector
<
DDim
>
shapes
()
const
override
{
return
reader_
->
shapes
();
}
protected:
ReaderBase
*
reader_
;
};
// file readers
// file readers
template
<
typename
T
>
template
<
typename
T
>
class
RandomReader
:
public
Reader
{
class
RandomReader
:
public
File
Reader
{
public:
public:
RandomReader
(
const
std
::
vector
<
DDim
>&
shapes
,
float
min
,
float
max
)
RandomReader
(
const
std
::
vector
<
DDim
>&
shapes
,
float
min
,
float
max
)
:
Reader
(
shapes
),
min_
(
min
),
max_
(
max
)
{
:
File
Reader
(
shapes
),
min_
(
min
),
max_
(
max
)
{
PADDLE_ENFORCE_LE
(
min
,
max
,
PADDLE_ENFORCE_LE
(
min
,
max
,
"'min' should be less than or equal to 'max'.(%f vs %f)"
,
"'min' should be less than or equal to 'max'.(%f vs %f)"
,
min
,
max
);
min
,
max
);
...
@@ -58,8 +74,8 @@ class RandomReader : public Reader {
...
@@ -58,8 +74,8 @@ class RandomReader : public Reader {
std
::
uniform_real_distribution
<
float
>
dist
(
min_
,
max_
);
std
::
uniform_real_distribution
<
float
>
dist
(
min_
,
max_
);
std
::
vector
<
LoDTensor
>
res
;
std
::
vector
<
LoDTensor
>
res
;
res
.
reserve
(
shapes
()
.
size
());
res
.
reserve
(
shapes
_
.
size
());
for
(
const
DDim
&
shape
:
shapes
()
)
{
for
(
const
DDim
&
shape
:
shapes
_
)
{
PADDLE_ENFORCE_GE
(
PADDLE_ENFORCE_GE
(
shape
.
size
(),
2
,
shape
.
size
(),
2
,
"The rank of input data should be 2 at least.(Now it's %d)"
,
"The rank of input data should be 2 at least.(Now it's %d)"
,
...
@@ -85,37 +101,27 @@ class RandomReader : public Reader {
...
@@ -85,37 +101,27 @@ class RandomReader : public Reader {
// decorators
// decorators
class
ShuffleReader
:
public
Reader
{
class
ShuffleReader
:
public
Reader
Decorator
{
public:
public:
ShuffleReader
(
Reader
*
reader
,
int
buffer_size
)
ShuffleReader
(
Reader
Base
*
reader
,
int
buffer_size
)
:
reader_
(
reader
),
buffer_size_
(
buffer_size
),
iteration_pos_
(
0
)
{
:
ReaderDecorator
(
reader
),
buffer_size_
(
buffer_size
),
iteration_pos_
(
0
)
{
buffer_
.
reserve
(
buffer_size
);
buffer_
.
reserve
(
buffer_size
);
}
}
std
::
vector
<
LoDTensor
>
ReadNext
()
override
;
std
::
vector
<
LoDTensor
>
ReadNext
()
override
;
bool
HasNext
()
const
override
{
return
reader_
->
HasNext
();
}
DDim
shape
(
size_t
idx
)
const
override
{
return
reader_
->
shape
(
idx
);
}
std
::
vector
<
DDim
>
shapes
()
const
override
{
return
reader_
->
shapes
();
}
private:
private:
Reader
*
reader_
;
int
buffer_size_
;
int
buffer_size_
;
std
::
vector
<
std
::
vector
<
LoDTensor
>>
buffer_
;
std
::
vector
<
std
::
vector
<
LoDTensor
>>
buffer_
;
size_t
iteration_pos_
;
size_t
iteration_pos_
;
};
};
class
BatchReader
:
public
Reader
{
class
BatchReader
:
public
Reader
Decorator
{
public:
public:
BatchReader
(
Reader
*
reader
,
int
batch_size
)
BatchReader
(
Reader
Base
*
reader
,
int
batch_size
)
:
reader_
(
reader
),
batch_size_
(
batch_size
)
{}
:
ReaderDecorator
(
reader
),
batch_size_
(
batch_size
)
{}
std
::
vector
<
LoDTensor
>
ReadNext
()
override
;
std
::
vector
<
LoDTensor
>
ReadNext
()
override
;
bool
HasNext
()
const
override
{
return
reader_
->
HasNext
();
};
DDim
shape
(
size_t
idx
)
const
override
{
return
reader_
->
shape
(
idx
);
}
std
::
vector
<
DDim
>
shapes
()
const
override
{
return
reader_
->
shapes
();
}
private:
private:
Reader
*
reader_
;
int
batch_size_
;
int
batch_size_
;
std
::
vector
<
std
::
vector
<
LoDTensor
>>
buffer_
;
std
::
vector
<
std
::
vector
<
LoDTensor
>>
buffer_
;
};
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录