Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
9b1c04f7
P
Paddle
项目概览
PaddlePaddle
/
Paddle
12 个月 前同步成功
通知
2292
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9b1c04f7
编写于
6月 29, 2017
作者:
Q
qingqing01
提交者:
GitHub
6月 29, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2631 from wanghaoshuang/fix_xmap
fix xmap_readers and refine flowers dataset
上级
f86b3ec9
01f44bff
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
81 addition
and
69 deletion
+81
-69
python/paddle/v2/dataset/__init__.py
python/paddle/v2/dataset/__init__.py
+2
-1
python/paddle/v2/dataset/flowers.py
python/paddle/v2/dataset/flowers.py
+42
-33
python/paddle/v2/dataset/tests/flowers_test.py
python/paddle/v2/dataset/tests/flowers_test.py
+2
-2
python/paddle/v2/reader/decorator.py
python/paddle/v2/reader/decorator.py
+23
-24
python/paddle/v2/reader/tests/decorator_test.py
python/paddle/v2/reader/tests/decorator_test.py
+10
-8
python/setup.py.in
python/setup.py.in
+2
-1
未找到文件。
python/paddle/v2/dataset/__init__.py
浏览文件 @
9b1c04f7
...
...
@@ -25,8 +25,9 @@ import uci_housing
import
sentiment
import
wmt14
import
mq2007
import
flowers
__all__
=
[
'mnist'
,
'imikolov'
,
'imdb'
,
'cifar'
,
'movielens'
,
'conll05'
,
'sentiment'
'uci_housing'
,
'wmt14'
,
'mq2007'
'uci_housing'
,
'wmt14'
,
'mq2007'
,
'flowers'
]
python/paddle/v2/dataset/flowers.py
浏览文件 @
9b1c04f7
...
...
@@ -34,9 +34,9 @@ from common import download
import
tarfile
import
scipy.io
as
scio
from
paddle.v2.image
import
*
from
paddle.v2.reader
import
*
import
os
import
numpy
as
np
import
paddle.v2
as
paddle
from
multiprocessing
import
cpu_count
__all__
=
[
'train'
,
'test'
,
'valid'
]
...
...
@@ -46,6 +46,12 @@ SETID_URL = 'http://www.robots.ox.ac.uk/~vgg/data/flowers/102/setid.mat'
DATA_MD5
=
'52808999861908f626f3c1f4e79d11fa'
LABEL_MD5
=
'e0620be6f572b9609742df49c70aed4d'
SETID_MD5
=
'a5357ecc9cb78c4bef273ce3793fc85c'
# In official 'readme', tstid is the flag of test data
# and trnid is the flag of train data. But test data is more than train data.
# So we exchange the train data and test data.
TRAIN_FLAG
=
'tstid'
TEST_FLAG
=
'trnid'
VALID_FLAG
=
'valid'
def
default_mapper
(
sample
):
...
...
@@ -53,8 +59,8 @@ def default_mapper(sample):
map image bytes data to type needed by model input layer
'''
img
,
label
=
sample
img
=
paddle
.
image
.
load_image_bytes
(
img
)
img
=
paddle
.
image
.
simple_transform
(
img
,
256
,
224
,
True
)
img
=
load_image_bytes
(
img
)
img
=
simple_transform
(
img
,
256
,
224
,
True
)
return
img
.
flatten
().
astype
(
'float32'
),
label
...
...
@@ -63,7 +69,8 @@ def reader_creator(data_file,
setid_file
,
dataset_name
,
mapper
=
default_mapper
,
buffered_size
=
1024
):
buffered_size
=
1024
,
use_xmap
=
True
):
'''
1. read images from tar file and
merge images into batch files in 102flowers.tgz_batch/
...
...
@@ -105,11 +112,13 @@ def reader_creator(data_file,
for
sample
,
label
in
itertools
.
izip
(
data
,
batch
[
'label'
]):
yield
sample
,
int
(
label
)
return
paddle
.
reader
.
xmap_readers
(
mapper
,
reader
,
cpu_count
(),
buffered_size
)
if
use_xmap
:
return
xmap_readers
(
mapper
,
reader
,
cpu_count
(),
buffered_size
)
else
:
return
map_readers
(
mapper
,
reader
)
def
train
(
mapper
=
default_mapper
,
buffered_size
=
1024
):
def
train
(
mapper
=
default_mapper
,
buffered_size
=
1024
,
use_xmap
=
True
):
'''
Create flowers training set reader.
It returns a reader, each sample in the reader is
...
...
@@ -128,11 +137,11 @@ def train(mapper=default_mapper, buffered_size=1024):
return
reader_creator
(
download
(
DATA_URL
,
'flowers'
,
DATA_MD5
),
download
(
LABEL_URL
,
'flowers'
,
LABEL_MD5
),
download
(
SETID_URL
,
'flowers'
,
SETID_MD5
),
'trnid'
,
mapper
,
buffered_size
)
download
(
SETID_URL
,
'flowers'
,
SETID_MD5
),
TRAIN_FLAG
,
mapper
,
buffered_size
,
use_xmap
)
def
test
(
mapper
=
default_mapper
,
buffered_size
=
1024
):
def
test
(
mapper
=
default_mapper
,
buffered_size
=
1024
,
use_xmap
=
True
):
'''
Create flowers test set reader.
It returns a reader, each sample in the reader is
...
...
@@ -151,11 +160,11 @@ def test(mapper=default_mapper, buffered_size=1024):
return
reader_creator
(
download
(
DATA_URL
,
'flowers'
,
DATA_MD5
),
download
(
LABEL_URL
,
'flowers'
,
LABEL_MD5
),
download
(
SETID_URL
,
'flowers'
,
SETID_MD5
),
'tstid'
,
mapper
,
buffered_size
)
download
(
SETID_URL
,
'flowers'
,
SETID_MD5
),
TEST_FLAG
,
mapper
,
buffered_size
,
use_xmap
)
def
valid
(
mapper
=
default_mapper
,
buffered_size
=
1024
):
def
valid
(
mapper
=
default_mapper
,
buffered_size
=
1024
,
use_xmap
=
True
):
'''
Create flowers validation set reader.
It returns a reader, each sample in the reader is
...
...
@@ -174,8 +183,8 @@ def valid(mapper=default_mapper, buffered_size=1024):
return
reader_creator
(
download
(
DATA_URL
,
'flowers'
,
DATA_MD5
),
download
(
LABEL_URL
,
'flowers'
,
LABEL_MD5
),
download
(
SETID_URL
,
'flowers'
,
SETID_MD5
),
'valid'
,
mapper
,
buffered_size
)
download
(
SETID_URL
,
'flowers'
,
SETID_MD5
),
VALID_FLAG
,
mapper
,
buffered_size
,
use_xmap
)
def
fetch
():
...
...
python/paddle/v2/dataset/tests/flowers_test.py
浏览文件 @
9b1c04f7
...
...
@@ -31,13 +31,13 @@ class TestFlowers(unittest.TestCase):
def
test_train
(
self
):
instances
,
max_label_value
=
self
.
check_reader
(
paddle
.
v2
.
dataset
.
flowers
.
train
())
self
.
assertEqual
(
instances
,
1020
)
self
.
assertEqual
(
instances
,
6149
)
self
.
assertEqual
(
max_label_value
,
102
)
def
test_test
(
self
):
instances
,
max_label_value
=
self
.
check_reader
(
paddle
.
v2
.
dataset
.
flowers
.
test
())
self
.
assertEqual
(
instances
,
6149
)
self
.
assertEqual
(
instances
,
1020
)
self
.
assertEqual
(
max_label_value
,
102
)
def
test_valid
(
self
):
...
...
python/paddle/v2/reader/decorator.py
浏览文件 @
9b1c04f7
...
...
@@ -248,9 +248,6 @@ def xmap_readers(mapper, reader, process_num, buffer_size, order=False):
:rtype: callable
"""
end
=
XmapEndSignal
()
in_queue
=
Queue
(
buffer_size
)
out_queue
=
Queue
(
buffer_size
)
out_order
=
[
0
]
# define a worker to read samples from reader to in_queue
def
read_worker
(
reader
,
in_queue
):
...
...
@@ -266,12 +263,6 @@ def xmap_readers(mapper, reader, process_num, buffer_size, order=False):
in_order
+=
1
in_queue
.
put
(
end
)
# start a read worker in a thread
target
=
order_read_worker
if
order
else
read_worker
t
=
Thread
(
target
=
target
,
args
=
(
reader
,
in_queue
))
t
.
daemon
=
True
t
.
start
()
# define a worker to handle samples from in_queue by mapper
# and put mapped samples into out_queue
def
handle_worker
(
in_queue
,
out_queue
,
mapper
):
...
...
@@ -298,6 +289,15 @@ def xmap_readers(mapper, reader, process_num, buffer_size, order=False):
in_queue
.
put
(
end
)
out_queue
.
put
(
end
)
def
xreader
():
in_queue
=
Queue
(
buffer_size
)
out_queue
=
Queue
(
buffer_size
)
out_order
=
[
0
]
# start a read worker in a thread
target
=
order_read_worker
if
order
else
read_worker
t
=
Thread
(
target
=
target
,
args
=
(
reader
,
in_queue
))
t
.
daemon
=
True
t
.
start
()
# start several handle_workers
target
=
order_handle_worker
if
order
else
handle_worker
args
=
(
in_queue
,
out_queue
,
mapper
,
out_order
)
if
order
else
(
...
...
@@ -310,7 +310,6 @@ def xmap_readers(mapper, reader, process_num, buffer_size, order=False):
for
w
in
workers
:
w
.
start
()
def
xreader
():
sample
=
out_queue
.
get
()
while
not
isinstance
(
sample
,
XmapEndSignal
):
yield
sample
...
...
python/paddle/v2/reader/tests/decorator_test.py
浏览文件 @
9b1c04f7
...
...
@@ -132,10 +132,12 @@ class TestXmap(unittest.TestCase):
for
order
in
orders
:
for
tNum
in
thread_nums
:
for
size
in
buffered_size
:
result
=
[]
for
i
in
paddle
.
v2
.
reader
.
xmap_readers
(
mapper
,
reader
=
paddle
.
v2
.
reader
.
xmap_readers
(
mapper
,
reader_creator_10
(
0
),
tNum
,
size
,
order
)():
tNum
,
size
,
order
)
for
n
in
xrange
(
3
):
result
=
[]
for
i
in
reader
():
result
.
append
(
i
)
if
not
order
:
result
.
sort
()
...
...
python/setup.py.in
浏览文件 @
9b1c04f7
...
...
@@ -15,7 +15,8 @@ setup_requires=["requests",
"protobuf==3.1",
"recordio",
"matplotlib",
"rarfile"]
"rarfile",
"scipy>=0.19.0"]
if '${CMAKE_SYSTEM_PROCESSOR}' not in ['arm', 'armv7-a', 'aarch64']:
setup_requires+=["opencv-python"]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录