Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
694e8945
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
694e8945
编写于
10月 18, 2018
作者:
Q
Qiao Longfei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add a base class for reader
上级
d981333e
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
34 addition
and
20 deletion
+34
-20
paddle/fluid/operators/reader/ctr_reader.cc
paddle/fluid/operators/reader/ctr_reader.cc
+34
-20
未找到文件。
paddle/fluid/operators/reader/ctr_reader.cc
浏览文件 @
694e8945
...
@@ -132,31 +132,36 @@ void CTRReader::ReadThread(const std::vector<std::string>& file_list,
...
@@ -132,31 +132,36 @@ void CTRReader::ReadThread(const std::vector<std::string>& file_list,
std
::
vector
<
int64_t
>
batch_label
;
std
::
vector
<
int64_t
>
batch_label
;
MultiGzipReader
reader
(
file_list
);
MultiGzipReader
reader
(
file_list
);
// read all files
for
(
int
i
=
0
;
i
<
batch_size
;
++
i
)
{
while
(
reader
.
HasNext
())
{
if
(
reader
.
HasNext
())
{
// read all files
reader
.
NextLine
(
&
line
);
for
(
int
i
=
0
;
i
<
batch_size
;
++
i
)
{
std
::
unordered_map
<
std
::
string
,
std
::
vector
<
int64_t
>>
slots_to_data
;
if
(
reader
.
HasNext
())
{
int64_t
label
;
reader
.
NextLine
(
&
line
);
parse_line
(
line
,
slots
,
&
label
,
&
slots_to_data
);
std
::
unordered_map
<
std
::
string
,
std
::
vector
<
int64_t
>>
slots_to_data
;
batch_data
.
push_back
(
slots_to_data
);
int64_t
label
;
batch_label
.
push_back
(
label
);
parse_line
(
line
,
slots
,
&
label
,
&
slots_to_data
);
}
else
{
batch_data
.
push_back
(
slots_to_data
);
break
;
batch_label
.
push_back
(
label
);
}
else
{
break
;
}
}
}
}
std
::
vector
<
framework
::
LoDTensor
>
lod_datas
;
std
::
vector
<
framework
::
LoDTensor
>
lod_datas
;
for
(
auto
&
slot
:
slots
)
{
for
(
auto
&
slots_to_data
:
batch_data
)
{
// first insert tensor for each slots
for
(
auto
&
slot
:
slots
)
{
std
::
vector
<
size_t
>
lod_data
{
0
};
std
::
vector
<
size_t
>
lod_data
{
0
};
std
::
vector
<
int64_t
>
batch_feasign
;
std
::
vector
<
int64_t
>
batch_feasign
;
std
::
vector
<
int64_t
>
batch_label
;
auto
&
feasign
=
slots_to_data
[
slot
];
for
(
size_t
i
=
0
;
i
<
batch_data
.
size
();
++
i
)
{
auto
&
feasign
=
batch_data
[
i
][
slot
];
lod_data
.
push_back
(
lod_data
.
back
()
+
feasign
.
size
());
batch_feasign
.
insert
(
feasign
.
end
(),
feasign
.
begin
(),
feasign
.
end
());
}
lod_data
.
push_back
(
lod_data
.
back
()
+
feasign
.
size
());
batch_feasign
.
insert
(
feasign
.
end
(),
feasign
.
begin
(),
feasign
.
end
());
framework
::
LoDTensor
lod_tensor
;
framework
::
LoDTensor
lod_tensor
;
framework
::
LoD
lod
{
lod_data
};
framework
::
LoD
lod
{
lod_data
};
lod_tensor
.
set_lod
(
lod
);
lod_tensor
.
set_lod
(
lod
);
...
@@ -166,8 +171,17 @@ void CTRReader::ReadThread(const std::vector<std::string>& file_list,
...
@@ -166,8 +171,17 @@ void CTRReader::ReadThread(const std::vector<std::string>& file_list,
memcpy
(
tensor_data
,
batch_feasign
.
data
(),
batch_feasign
.
size
());
memcpy
(
tensor_data
,
batch_feasign
.
data
(),
batch_feasign
.
size
());
lod_datas
.
push_back
(
lod_tensor
);
lod_datas
.
push_back
(
lod_tensor
);
}
}
// insert label tensor
framework
::
LoDTensor
label_tensor
;
int64_t
*
label_tensor_data
=
label_tensor
.
mutable_data
<
int64_t
>
(
framework
::
make_ddim
({
1
,
static_cast
<
int64_t
>
(
batch_label
.
size
())}),
platform
::
CPUPlace
());
memcpy
(
label_tensor_data
,
batch_label
.
data
(),
batch_label
.
size
());
lod_datas
.
push_back
(
label_tensor
);
queue
->
Push
(
lod_datas
);
}
}
queue
->
Push
(
lod_datas
);
}
}
}
// namespace reader
}
// namespace reader
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录