Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
7eedced8
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
7eedced8
编写于
3月 12, 2018
作者:
Y
Yu Yang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polish RecordIO
上级
cfca8a3a
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
47 addition
and
14 deletion
+47
-14
paddle/fluid/framework/reader.h
paddle/fluid/framework/reader.h
+6
-0
paddle/fluid/operators/reader/create_double_buffer_reader_op.cc
.../fluid/operators/reader/create_double_buffer_reader_op.cc
+4
-0
paddle/fluid/operators/reader/create_random_data_generator_op.cc
...fluid/operators/reader/create_random_data_generator_op.cc
+2
-0
paddle/fluid/recordio/chunk.cc
paddle/fluid/recordio/chunk.cc
+1
-0
paddle/fluid/recordio/scanner.cc
paddle/fluid/recordio/scanner.cc
+2
-2
paddle/fluid/recordio/scanner.h
paddle/fluid/recordio/scanner.h
+1
-1
paddle/fluid/recordio/writer_scanner_test.cc
paddle/fluid/recordio/writer_scanner_test.cc
+25
-0
python/paddle/fluid/tests/unittests/test_recordio_reader.py
python/paddle/fluid/tests/unittests/test_recordio_reader.py
+6
-11
未找到文件。
paddle/fluid/framework/reader.h
浏览文件 @
7eedced8
...
...
@@ -33,6 +33,8 @@ class ReaderBase {
std
::
vector
<
DDim
>
shapes
()
const
{
return
shapes_
;
}
void
set_shapes
(
const
std
::
vector
<
DDim
>&
shapes
)
{
shapes_
=
shapes
;
}
virtual
bool
HasNext
()
const
=
0
;
virtual
~
ReaderBase
()
{}
protected:
...
...
@@ -53,6 +55,8 @@ class DecoratedReader : public ReaderBase {
void
ReInit
()
override
{
reader_
->
ReInit
();
}
bool
HasNext
()
const
override
{
return
reader_
->
HasNext
();
}
protected:
ReaderBase
*
reader_
;
};
...
...
@@ -74,6 +78,8 @@ class ReaderHolder {
reader_
->
set_shapes
(
shapes
);
}
bool
HasNext
()
const
{
return
reader_
->
HasNext
();
}
private:
std
::
unique_ptr
<
ReaderBase
>
reader_
;
};
...
...
paddle/fluid/operators/reader/create_double_buffer_reader_op.cc
浏览文件 @
7eedced8
...
...
@@ -37,6 +37,8 @@ class DoubleBufferReader : public framework::DecoratedReader {
~
DoubleBufferReader
()
{
buffer_
->
Close
();
}
bool
HasNext
()
const
override
;
private:
void
PrefetchThreadFunc
();
...
...
@@ -106,6 +108,8 @@ void DoubleBufferReader::PrefetchThreadFunc() {
}
}
bool
DoubleBufferReader
::
HasNext
()
const
{
PADDLE_THROW
(
"Not Implemented"
);
}
}
// namespace reader
}
// namespace operators
}
// namespace paddle
...
...
paddle/fluid/operators/reader/create_random_data_generator_op.cc
浏览文件 @
7eedced8
...
...
@@ -52,6 +52,8 @@ class RandomDataGenerator : public framework::FileReader {
void
ReInit
()
override
{
return
;
}
bool
HasNext
()
const
override
{
return
true
;
}
private:
float
min_
;
float
max_
;
...
...
paddle/fluid/recordio/chunk.cc
浏览文件 @
7eedced8
...
...
@@ -146,6 +146,7 @@ bool Chunk::Parse(std::istream& sin) {
std
::
string
buf
;
buf
.
resize
(
rec_len
);
stream
.
read
(
&
buf
[
0
],
rec_len
);
PADDLE_ENFORCE_EQ
(
rec_len
,
stream
.
gcount
());
Add
(
buf
);
}
return
true
;
...
...
paddle/fluid/recordio/scanner.cc
浏览文件 @
7eedced8
...
...
@@ -32,9 +32,9 @@ void Scanner::Reset() {
ParseNextChunk
();
}
const
std
::
string
&
Scanner
::
Next
()
{
std
::
string
Scanner
::
Next
()
{
PADDLE_ENFORCE
(
!
eof_
,
"StopIteration"
);
auto
&
rec
=
cur_chunk_
.
Record
(
offset_
++
);
auto
rec
=
cur_chunk_
.
Record
(
offset_
++
);
if
(
offset_
==
cur_chunk_
.
NumRecords
())
{
ParseNextChunk
();
}
...
...
paddle/fluid/recordio/scanner.h
浏览文件 @
7eedced8
...
...
@@ -28,7 +28,7 @@ public:
void
Reset
();
const
std
::
string
&
Next
();
std
::
string
Next
();
bool
HasNext
()
const
;
...
...
paddle/fluid/recordio/writer_scanner_test.cc
浏览文件 @
7eedced8
...
...
@@ -41,4 +41,29 @@ TEST(WriterScanner, Normal) {
ASSERT_EQ
(
"CDE"
,
scanner
.
Next
());
ASSERT_FALSE
(
scanner
.
HasNext
());
}
}
TEST
(
WriterScanner
,
TinyChunk
)
{
std
::
stringstream
*
stream
=
new
std
::
stringstream
();
{
paddle
::
recordio
::
Writer
writer
(
stream
,
paddle
::
recordio
::
Compressor
::
kNoCompress
,
2
/*max chunk num*/
);
writer
.
Write
(
"ABC"
);
writer
.
Write
(
"BCD"
);
writer
.
Write
(
"CDE"
);
writer
.
Write
(
"DEFG"
);
writer
.
Flush
();
}
{
stream
->
seekg
(
0
,
std
::
ios
::
beg
);
std
::
unique_ptr
<
std
::
istream
>
stream_ptr
(
stream
);
paddle
::
recordio
::
Scanner
scanner
(
std
::
move
(
stream_ptr
));
ASSERT_TRUE
(
scanner
.
HasNext
());
ASSERT_EQ
(
scanner
.
Next
(),
"ABC"
);
ASSERT_EQ
(
scanner
.
Next
(),
"BCD"
);
ASSERT_EQ
(
scanner
.
Next
(),
"CDE"
);
ASSERT_EQ
(
scanner
.
Next
(),
"DEFG"
);
ASSERT_FALSE
(
scanner
.
HasNext
());
}
}
\ No newline at end of file
python/paddle/fluid/tests/unittests/test_recordio_reader.py
浏览文件 @
7eedced8
...
...
@@ -55,15 +55,10 @@ class TestRecordIO(unittest.TestCase):
exe
.
run
(
fluid
.
default_startup_program
())
avg_loss_np
=
[]
for
i
in
xrange
(
2
):
# 2 pass
batch_id
=
0
while
not
data_file
.
eof
():
try
:
batch_id
+=
1
tmp
,
=
exe
.
run
(
fetch_list
=
[
avg_loss
])
avg_loss_np
.
append
(
tmp
)
except
:
print
batch_id
break
data_file
.
reset
()
# train a pass
while
not
data_file
.
eof
():
tmp
,
=
exe
.
run
(
fetch_list
=
[
avg_loss
])
avg_loss_np
.
append
(
tmp
)
data_file
.
reset
()
self
.
assertLess
(
avg_loss_np
[
-
1
],
avg_loss_np
[
0
])
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录