Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleFL
提交
b85f7364
P
PaddleFL
项目概览
PaddlePaddle
/
PaddleFL
通知
35
Star
5
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
6
列表
看板
标记
里程碑
合并请求
4
Wiki
3
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleFL
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
6
Issue
6
列表
看板
标记
里程碑
合并请求
4
合并请求
4
Pages
分析
分析
仓库分析
DevOps
Wiki
3
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
b85f7364
编写于
5月 28, 2020
作者:
J
jingqinghe
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add detection demo
上级
8a8cc243
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
241 addition
and
0 deletion
+241
-0
python/paddle_fl/paddle_fl/examples/detection_demo/download.sh
...n/paddle_fl/paddle_fl/examples/detection_demo/download.sh
+2
-0
python/paddle_fl/paddle_fl/examples/detection_demo/fl_master.py
.../paddle_fl/paddle_fl/examples/detection_demo/fl_master.py
+35
-0
python/paddle_fl/paddle_fl/examples/detection_demo/fl_scheduler.py
...ddle_fl/paddle_fl/examples/detection_demo/fl_scheduler.py
+24
-0
python/paddle_fl/paddle_fl/examples/detection_demo/fl_server.py
.../paddle_fl/paddle_fl/examples/detection_demo/fl_server.py
+29
-0
python/paddle_fl/paddle_fl/examples/detection_demo/fl_trainer.py
...paddle_fl/paddle_fl/examples/detection_demo/fl_trainer.py
+132
-0
python/paddle_fl/paddle_fl/examples/detection_demo/run.sh
python/paddle_fl/paddle_fl/examples/detection_demo/run.sh
+18
-0
python/paddle_fl/paddle_fl/examples/generate_job_from_program/fl_trainer.py
...addle_fl/examples/generate_job_from_program/fl_trainer.py
+1
-0
未找到文件。
python/paddle_fl/paddle_fl/examples/detection_demo/download.sh
0 → 100644
浏览文件 @
b85f7364
wget
--no-check-certificate
https://paddlefl.bj.bcebos.com/datasets/fl_fruit.tar.gz
tar
-xf
fl_fruit.tar.gz
python/paddle_fl/paddle_fl/examples/detection_demo/fl_master.py
0 → 100644
浏览文件 @
b85f7364
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import
math
import
paddle_fl.paddle_fl
as
fl
import
paddle.fluid
as
fluid
from
paddle_fl.paddle_fl.core.master.job_generator
import
JobGenerator
from
paddle_fl.paddle_fl.core.strategy.fl_strategy_base
import
FLStrategyFactory
# Fedavg
build_strategy
=
FLStrategyFactory
()
build_strategy
.
fed_avg
=
True
build_strategy
.
inner_step
=
5
strategy
=
build_strategy
.
create_fl_strategy
()
endpoints
=
[
"127.0.0.1:8181"
]
output
=
"fl_job_config"
program_file
=
"faster_rcnn_program"
job_generator
=
JobGenerator
()
job_generator
.
generate_fl_job_from_program
(
strategy
=
strategy
,
endpoints
=
endpoints
,
worker_num
=
2
,
program_input
=
program_file
,
output
=
output
)
python/paddle_fl/paddle_fl/examples/detection_demo/fl_scheduler.py
0 → 100644
浏览文件 @
b85f7364
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from
paddle_fl.paddle_fl.core.scheduler.agent_master
import
FLScheduler
worker_num
=
2
server_num
=
1
#Define number of worker/server and the port for scheduler
scheduler
=
FLScheduler
(
worker_num
,
server_num
,
port
=
9091
)
scheduler
.
set_sample_worker_num
(
2
)
scheduler
.
init_env
()
print
(
"init env done."
)
scheduler
.
start_fl_training
()
python/paddle_fl/paddle_fl/examples/detection_demo/fl_server.py
0 → 100644
浏览文件 @
b85f7364
# Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#import paddle_fl.paddle_fl as fl
import
paddle_fl
as
fl
import
paddle.fluid
as
fluid
from
paddle_fl.paddle_fl.core.server.fl_server
import
FLServer
from
paddle_fl.paddle_fl.core.master.fl_job
import
FLRunTimeJob
server
=
FLServer
()
server_id
=
0
job_path
=
"fl_job_config"
job
=
FLRunTimeJob
()
job
.
load_server_job
(
job_path
,
server_id
)
job
.
_scheduler_ep
=
"127.0.0.1:9091"
# IP address for scheduler
server
.
set_server_job
(
job
)
server
.
_current_ep
=
"127.0.0.1:8181"
# IP address for server
server
.
start
()
python/paddle_fl/paddle_fl/examples/detection_demo/fl_trainer.py
0 → 100644
浏览文件 @
b85f7364
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from
paddle_fl.paddle_fl.core.trainer.fl_trainer
import
FLTrainerFactory
from
paddle_fl.paddle_fl.core.master.fl_job
import
FLRunTimeJob
import
numpy
as
np
import
sys
import
paddle
import
pickle
import
paddle.fluid
as
fluid
import
logging
import
math
import
unittest
import
os
from
ppdet.data.source.voc
import
VOCDataSet
from
ppdet.data.reader
import
Reader
from
ppdet.utils.download
import
get_path
from
ppdet.utils.download
import
DATASET_HOME
from
ppdet.data.transform.operators
import
DecodeImage
,
RandomFlipImage
,
NormalizeImage
,
ResizeImage
,
Permute
from
ppdet.data.transform.batch_operators
import
PadBatch
trainer_id
=
int
(
sys
.
argv
[
1
])
# trainer id for each guest
class
DataReader
():
def
__init__
(
self
):
""" setup
"""
self
.
root_path
=
'/path/to/your/fl_fruit'
self
.
anno_path
=
'/path/to/your/fl_fruit/train'
+
str
(
trainer_id
)
+
'.txt'
self
.
image_dir
=
'/path/to/your/fl_fruit/JPEGImages'
def
tearDownClass
(
self
):
""" tearDownClass """
pass
def
test_loader
(
self
):
coco_loader
=
VOCDataSet
(
dataset_dir
=
self
.
image_dir
,
image_dir
=
self
.
root_path
,
anno_path
=
self
.
anno_path
,
sample_num
=
240
,
use_default_label
=
False
,
label_list
=
'/path/to/your/fl_fruit/label_list.txt'
)
sample_trans
=
[
DecodeImage
(
to_rgb
=
True
),
RandomFlipImage
(),
NormalizeImage
(
mean
=
[
0.485
,
0.456
,
0.406
],
std
=
[
0.229
,
0.224
,
0.225
],
is_scale
=
True
,
is_channel_first
=
False
),
ResizeImage
(
target_size
=
800
,
max_size
=
1333
,
interp
=
1
),
Permute
(
to_bgr
=
False
)
]
batch_trans
=
[
PadBatch
(
pad_to_stride
=
32
,
use_padded_im_info
=
True
),
]
inputs_def
=
{
'fields'
:
[
'image'
,
'im_info'
,
'im_id'
,
'gt_bbox'
,
'gt_class'
,
'is_crowd'
],
}
data_loader
=
Reader
(
coco_loader
,
sample_transforms
=
sample_trans
,
batch_transforms
=
batch_trans
,
batch_size
=
1
,
shuffle
=
True
,
drop_empty
=
True
,
inputs_def
=
inputs_def
)()
return
data_loader
job_path
=
"fl_job_config"
job
=
FLRunTimeJob
()
job
.
load_trainer_job
(
job_path
,
trainer_id
)
job
.
_scheduler_ep
=
"127.0.0.1:9091"
# Inform scheduler IP address to trainer
trainer
=
FLTrainerFactory
().
create_fl_trainer
(
job
)
trainer
.
_current_ep
=
"127.0.0.1:{}"
.
format
(
9000
+
trainer_id
)
trainer
.
start
(
fluid
.
CUDAPlace
(
trainer_id
))
test_program
=
trainer
.
_main_program
.
clone
(
for_test
=
True
)
image
=
fluid
.
layers
.
data
(
name
=
'image'
,
shape
=
[
3
,
None
,
None
],
dtype
=
'float32'
,
lod_level
=
0
)
im_info
=
fluid
.
layers
.
data
(
name
=
'im_info'
,
shape
=
[
None
,
3
],
dtype
=
'float32'
,
lod_level
=
0
)
im_id
=
fluid
.
layers
.
data
(
name
=
'im_id'
,
shape
=
[
None
,
1
],
dtype
=
'int64'
,
lod_level
=
0
)
gt_bbox
=
fluid
.
layers
.
data
(
name
=
'gt_bbox'
,
shape
=
[
None
,
4
],
dtype
=
'float32'
,
lod_level
=
1
)
gt_class
=
fluid
.
layers
.
data
(
name
=
'gt_class'
,
shape
=
[
None
,
1
],
dtype
=
'int32'
,
lod_level
=
1
)
is_crowd
=
fluid
.
layers
.
data
(
name
=
'is_crowd'
,
shape
=
[
None
,
1
],
dtype
=
'int32'
,
lod_level
=
1
)
place
=
fluid
.
CUDAPlace
(
trainer_id
)
feeder
=
fluid
.
DataFeeder
(
feed_list
=
[
image
,
im_info
,
im_id
,
gt_bbox
,
gt_class
,
is_crowd
],
place
=
place
)
output_folder
=
"5_model_node%d"
%
trainer_id
epoch_id
=
0
step
=
0
para_dir
=
"faster_rcnn_program"
while
not
trainer
.
stop
():
epoch_id
+=
1
if
epoch_id
>
120
:
break
print
(
"epoch %d start train"
%
(
epoch_id
))
test_class
=
DataReader
()
data_loader
=
test_class
.
test_loader
()
for
step_id
,
data
in
enumerate
(
data_loader
):
acc
=
trainer
.
run
(
feeder
.
feed
(
data
),
fetch
=
[
'sum_0.tmp_0'
])
step
+=
1
print
(
"step: {}, loss: {}"
.
format
(
step
,
acc
))
if
trainer_id
==
0
:
save_dir
=
(
output_folder
+
"/epoch_%d"
)
%
epoch_id
trainer
.
save
(
para_dir
,
save_dir
)
python/paddle_fl/paddle_fl/examples/detection_demo/run.sh
0 → 100644
浏览文件 @
b85f7364
wget
--no-check-certificate
https://paddlefl.bj.bcebos.com/detection_programs/faster_rcnn_program.tar.gz
tar
-xf
faster_rcnn_program.tar.gz
unset
http_proxy
unset
https_proxy
export
PYTHONPATH
=
/path/to/PaddleDetection
CUDA_VISIBLE_DEVICES
=
0,1
python fl_master.py
sleep
2
python
-u
fl_scheduler.py
>
scheduler.log &
sleep
2
python
-u
fl_server.py
>
server0.log &
sleep
2
python
-u
fl_trainer.py 0
>
5_trainer0.log &
sleep
2
python
-u
fl_trainer.py 1
>
5_trainer1.log &
sleep
2
python/paddle_fl/paddle_fl/examples/generate_job_from_program/fl_trainer.py
浏览文件 @
b85f7364
...
...
@@ -61,6 +61,7 @@ def train_test(train_test_program, train_test_feed, train_test_reader):
return
acc_val_mean
para_dir
=
'load_file'
output_folder
=
"model_node%d"
%
trainer_id
epoch_id
=
0
step
=
0
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录