Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
book
提交
59f4265a
B
book
项目概览
PaddlePaddle
/
book
通知
16
Star
4
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
40
列表
看板
标记
里程碑
合并请求
37
Wiki
5
Wiki
分析
仓库
DevOps
项目成员
Pages
B
book
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
40
Issue
40
列表
看板
标记
里程碑
合并请求
37
合并请求
37
Pages
分析
分析
仓库分析
DevOps
Wiki
5
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
59f4265a
编写于
5月 23, 2019
作者:
u010070587
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add 05.recommender_system ce
上级
a19f5f00
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
79 addition
and
8 deletion
+79
-8
05.recommender_system/.run_ce.sh
05.recommender_system/.run_ce.sh
+4
-0
05.recommender_system/_ce.py
05.recommender_system/_ce.py
+36
-0
05.recommender_system/train.py
05.recommender_system/train.py
+39
-8
未找到文件。
05.recommender_system/.run_ce.sh
0 → 100755
浏览文件 @
59f4265a
#!/bin/bash
#This file is only used for continuous evaluation.
python train.py
--enable_ce
| python _ce.py
05.recommender_system/_ce.py
0 → 100644
浏览文件 @
59f4265a
### This file is only used for continuous evaluation test!
from
__future__
import
print_function
from
__future__
import
division
from
__future__
import
absolute_import
import
os
import
sys
sys
.
path
.
append
(
os
.
environ
[
'ceroot'
])
from
kpi
import
CostKpi
test_cost_kpi
=
CostKpi
(
'test_cost'
,
0.02
,
0
,
actived
=
True
,
desc
=
'test cost'
)
tracking_kpis
=
[
test_cost_kpi
]
def
parse_log
(
log
):
for
line
in
log
.
split
(
'
\n
'
):
fs
=
line
.
strip
().
split
(
'
\t
'
)
print
(
fs
)
if
len
(
fs
)
==
3
and
fs
[
0
]
==
'kpis'
:
kpi_name
=
fs
[
1
]
kpi_value
=
float
(
fs
[
2
])
yield
kpi_name
,
kpi_value
def
log_to_ce
(
log
):
kpi_tracker
=
{}
for
kpi
in
tracking_kpis
:
kpi_tracker
[
kpi
.
name
]
=
kpi
for
(
kpi_name
,
kpi_value
)
in
parse_log
(
log
):
print
(
kpi_name
,
kpi_value
)
kpi_tracker
[
kpi_name
].
add_record
(
kpi_value
)
kpi_tracker
[
kpi_name
].
persist
()
if
__name__
==
'__main__'
:
log
=
sys
.
stdin
.
read
()
log_to_ce
(
log
)
05.recommender_system/train.py
浏览文件 @
59f4265a
...
...
@@ -15,6 +15,7 @@
from
__future__
import
print_function
import
math
import
sys
import
argparse
import
numpy
as
np
import
paddle
import
paddle.fluid
as
fluid
...
...
@@ -22,9 +23,21 @@ import paddle.fluid.layers as layers
import
paddle.fluid.nets
as
nets
IS_SPARSE
=
True
USE_GPU
=
False
BATCH_SIZE
=
256
PASS_NUM
=
100
def
parse_args
():
parser
=
argparse
.
ArgumentParser
(
"recommender_system"
)
parser
.
add_argument
(
'--enable_ce'
,
action
=
'store_true'
,
help
=
"If set, run the task with continuous evaluation logs."
)
parser
.
add_argument
(
'--use_gpu'
,
type
=
int
,
default
=
0
,
help
=
"Whether to use GPU or not."
)
parser
.
add_argument
(
'--num_epochs'
,
type
=
int
,
default
=
1
,
help
=
"number of epochs."
)
args
=
parser
.
parse_args
()
return
args
def
get_usr_combined_features
():
...
...
@@ -154,11 +167,18 @@ def optimizer_func():
def
train
(
use_cuda
,
params_dirname
):
place
=
fluid
.
CUDAPlace
(
0
)
if
use_cuda
else
fluid
.
CPUPlace
()
train_reader
=
paddle
.
batch
(
paddle
.
reader
.
shuffle
(
paddle
.
dataset
.
movielens
.
train
(),
buf_size
=
8192
),
batch_size
=
BATCH_SIZE
)
test_reader
=
paddle
.
batch
(
paddle
.
dataset
.
movielens
.
test
(),
batch_size
=
BATCH_SIZE
)
if
args
.
enable_ce
:
train_reader
=
paddle
.
batch
(
paddle
.
dataset
.
movielens
.
train
(),
batch_size
=
BATCH_SIZE
)
test_reader
=
paddle
.
batch
(
paddle
.
dataset
.
movielens
.
test
(),
batch_size
=
BATCH_SIZE
)
else
:
train_reader
=
paddle
.
batch
(
paddle
.
reader
.
shuffle
(
paddle
.
dataset
.
movielens
.
train
(),
buf_size
=
8192
),
batch_size
=
BATCH_SIZE
)
test_reader
=
paddle
.
batch
(
paddle
.
dataset
.
movielens
.
test
(),
batch_size
=
BATCH_SIZE
)
feed_order
=
[
'user_id'
,
'gender_id'
,
'age_id'
,
'job_id'
,
'movie_id'
,
'category_id'
,
...
...
@@ -167,6 +187,10 @@ def train(use_cuda, params_dirname):
main_program
=
fluid
.
default_main_program
()
star_program
=
fluid
.
default_startup_program
()
if
args
.
enable_ce
:
main_program
.
random_seed
=
90
star_program
.
random_seed
=
90
scale_infer
,
avg_cost
=
inference_program
()
test_program
=
main_program
.
clone
(
for_test
=
True
)
...
...
@@ -212,6 +236,10 @@ def train(use_cuda, params_dirname):
# if test_avg_cost < 4.0: # Change this number to adjust accuracy
if
batch_id
==
20
:
if
args
.
enable_ce
:
print
(
"kpis
\t
test_cost
\t
%f"
%
float
(
test_avg_cost
))
if
params_dirname
is
not
None
:
fluid
.
io
.
save_inference_model
(
params_dirname
,
[
"user_id"
,
"gender_id"
,
"age_id"
,
"job_id"
,
...
...
@@ -319,4 +347,7 @@ def main(use_cuda):
if
__name__
==
'__main__'
:
main
(
USE_GPU
)
args
=
parse_args
()
PASS_NUM
=
args
.
num_epochs
use_cuda
=
args
.
use_gpu
main
(
use_cuda
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录