Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleFL
提交
757ca7c3
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看板
提交
757ca7c3
编写于
1月 13, 2020
作者:
Q
qjing666
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix dataset conflict issue in single machine simulation
上级
c14e5c83
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
21 addition
and
21 deletion
+21
-21
paddle_fl/dataset/femnist.py
paddle_fl/dataset/femnist.py
+21
-21
未找到文件。
paddle_fl/dataset/femnist.py
浏览文件 @
757ca7c3
...
...
@@ -24,18 +24,18 @@ def train(trainer_id,inner_step,batch_size,count_by_step):
tar_path
=
data_path
+
".tar.gz"
if
not
os
.
path
.
exists
(
target_path
):
os
.
system
(
"mkdir trainer%d_data"
%
trainer_id
)
if
not
os
.
path
.
exists
(
data_path
):
print
(
"Preparing data..."
)
if
not
os
.
path
.
exists
(
tar_path
):
download
(
"https://paddlefl.bj.bcebos.com/leaf/femnist_data.tar.gz"
,
tar_path
)
extract
(
tar_path
,
target_path
)
def
train_data
():
train_file
=
open
(
"./trainer%d_data/femnist_data/train/all_data_%d_niid_0_keep_0_train_9.json"
%
(
trainer_id
,
trainer_id
),
'r'
)
json_train
=
json
.
load
(
train_file
)
users
=
json_train
[
"users"
]
rand
=
random
.
randrange
(
0
,
len
(
users
))
# random choose a user from each trainer
cur_user
=
users
[
rand
]
print
(
'training using '
+
cur_user
)
if
not
os
.
path
.
exists
(
data_path
):
print
(
"Preparing data..."
)
if
not
os
.
path
.
exists
(
tar_path
):
download
(
"https://paddlefl.bj.bcebos.com/leaf/femnist_data.tar.gz"
,
tar_path
)
extract
(
tar_path
,
target_path
)
def
train_data
():
train_file
=
open
(
"./trainer%d_data/femnist_data/train/all_data_%d_niid_0_keep_0_train_9.json"
%
(
trainer_id
,
trainer_id
),
'r'
)
json_train
=
json
.
load
(
train_file
)
users
=
json_train
[
"users"
]
rand
=
random
.
randrange
(
0
,
len
(
users
))
# random choose a user from each trainer
cur_user
=
users
[
rand
]
print
(
'training using '
+
cur_user
)
train_images
=
json_train
[
"user_data"
][
cur_user
][
'x'
]
train_labels
=
json_train
[
"user_data"
][
cur_user
][
'y'
]
if
count_by_step
:
...
...
@@ -45,9 +45,9 @@ def train(trainer_id,inner_step,batch_size,count_by_step):
for
i
in
xrange
(
len
(
train_images
)):
yield
train_images
[
i
],
train_labels
[
i
]
train_file
.
close
()
train_file
.
close
()
return
train_data
return
train_data
def
test
(
trainer_id
,
inner_step
,
batch_size
,
count_by_step
):
target_path
=
"trainer%d_data"
%
trainer_id
...
...
@@ -60,18 +60,18 @@ def test(trainer_id,inner_step,batch_size,count_by_step):
if
not
os
.
path
.
exists
(
tar_path
):
download
(
"https://paddlefl.bj.bcebos.com/leaf/femnist_data.tar.gz"
,
tar_path
)
extract
(
tar_path
,
target_path
)
def
test_data
():
test_file
=
open
(
"./trainer%d_data/femnist_data/test/all_data_%d_niid_0_keep_0_test_9.json"
%
(
trainer_id
,
trainer_id
),
'r'
)
json_test
=
json
.
load
(
test_file
)
users
=
json_test
[
"users"
]
for
user
in
users
:
def
test_data
():
test_file
=
open
(
"./trainer%d_data/femnist_data/test/all_data_%d_niid_0_keep_0_test_9.json"
%
(
trainer_id
,
trainer_id
),
'r'
)
json_test
=
json
.
load
(
test_file
)
users
=
json_test
[
"users"
]
for
user
in
users
:
test_images
=
json_test
[
'user_data'
][
user
][
'x'
]
test_labels
=
json_test
[
'user_data'
][
user
][
'y'
]
for
i
in
xrange
(
len
(
test_images
)):
yield
test_images
[
i
],
test_labels
[
i
]
test_file
.
close
()
test_file
.
close
()
return
test_data
return
test_data
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录