Skip to content

Commit 14eb5b8

Browse files
committed
rename fetch_all to fetch; add fetch_all function
1 parent 7b72c79 commit 14eb5b8

File tree

10 files changed

+42
-35
lines changed

10 files changed

+42
-35
lines changed

python/paddle/v2/dataset/cifar.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import cPickle
2121
import itertools
2222
import numpy
23-
import paddle.v2.dataset.common
23+
from common import download
2424
import tarfile
2525

2626
__all__ = ['train100', 'test100', 'train10', 'test10']
@@ -55,28 +55,23 @@ def reader():
5555

5656
def train100():
5757
return reader_creator(
58-
paddle.v2.dataset.common.download(CIFAR100_URL, 'cifar', CIFAR100_MD5),
59-
'train')
58+
download(CIFAR100_URL, 'cifar', CIFAR100_MD5), 'train')
6059

6160

6261
def test100():
63-
return reader_creator(
64-
paddle.v2.dataset.common.download(CIFAR100_URL, 'cifar', CIFAR100_MD5),
65-
'test')
62+
return reader_creator(download(CIFAR100_URL, 'cifar', CIFAR100_MD5), 'test')
6663

6764

6865
def train10():
6966
return reader_creator(
70-
paddle.v2.dataset.common.download(CIFAR10_URL, 'cifar', CIFAR10_MD5),
71-
'data_batch')
67+
download(CIFAR10_URL, 'cifar', CIFAR10_MD5), 'data_batch')
7268

7369

7470
def test10():
7571
return reader_creator(
76-
paddle.v2.dataset.common.download(CIFAR10_URL, 'cifar', CIFAR10_MD5),
77-
'test_batch')
72+
download(CIFAR10_URL, 'cifar', CIFAR10_MD5), 'test_batch')
7873

7974

80-
def fetch_data():
81-
paddle.v2.dataset.common.download(CIFAR10_URL, 'cifar', CIFAR10_MD5)
82-
paddle.v2.dataset.common.download(CIFAR100_URL, 'cifar', CIFAR100_MD5)
75+
def fetch():
76+
download(CIFAR10_URL, 'cifar', CIFAR10_MD5)
77+
download(CIFAR100_URL, 'cifar', CIFAR100_MD5)

python/paddle/v2/dataset/common.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import os
1818
import shutil
1919
import sys
20+
import importlib
21+
import paddle.v2.dataset
2022

2123
__all__ = ['DATA_HOME', 'download', 'md5file']
2224

@@ -69,3 +71,13 @@ def dict_add(a_dict, ele):
6971
a_dict[ele] += 1
7072
else:
7173
a_dict[ele] = 1
74+
75+
76+
def fetch_all():
77+
for module_name in filter(lambda x: not x.startswith("__"),
78+
dir(paddle.v2.dataset)):
79+
if "fetch" in dir(
80+
importlib.import_module("paddle.v2.dataset.%s" % module_name)):
81+
getattr(
82+
importlib.import_module("paddle.v2.dataset.%s" % module_name),
83+
"fetch")()

python/paddle/v2/dataset/conll05.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,9 @@ def test():
198198
return reader_creator(reader, word_dict, verb_dict, label_dict)
199199

200200

201-
def fetch_data():
202-
paddle.v2.dataset.common.download(WORDDICT_URL, 'conll05st', WORDDICT_MD5)
203-
paddle.v2.dataset.common.download(VERBDICT_URL, 'conll05st', VERBDICT_MD5)
204-
paddle.v2.dataset.common.download(TRGDICT_URL, 'conll05st', TRGDICT_MD5)
205-
paddle.v2.dataset.common.download(EMB_URL, 'conll05st', EMB_MD5)
206-
paddle.v2.dataset.common.download(DATA_URL, 'conll05st', DATA_MD5)
201+
def fetch():
202+
download(WORDDICT_URL, 'conll05st', WORDDICT_MD5)
203+
download(VERBDICT_URL, 'conll05st', VERBDICT_MD5)
204+
download(TRGDICT_URL, 'conll05st', TRGDICT_MD5)
205+
download(EMB_URL, 'conll05st', EMB_MD5)
206+
download(DATA_URL, 'conll05st', DATA_MD5)

python/paddle/v2/dataset/imdb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,5 +125,5 @@ def word_dict():
125125
re.compile("aclImdb/((train)|(test))/((pos)|(neg))/.*\.txt$"), 150)
126126

127127

128-
def fetch_data():
128+
def fetch():
129129
paddle.v2.dataset.common.download(URL, 'imdb', MD5)

python/paddle/v2/dataset/imikolov.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,5 @@ def test(word_idx, n):
9191
return reader_creator('./simple-examples/data/ptb.valid.txt', word_idx, n)
9292

9393

94-
def fetch_data():
94+
def fetch():
9595
paddle.v2.dataset.common.download(URL, "imikolov", MD5)

python/paddle/v2/dataset/mnist.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ def test():
108108
TEST_LABEL_MD5), 100)
109109

110110

111-
def fetch_data():
111+
def fetch():
112112
paddle.v2.dataset.common.download(TRAIN_IMAGE_URL, 'mnist', TRAIN_IMAGE_MD5)
113113
paddle.v2.dataset.common.download(TRAIN_LABEL_URL, 'mnist', TRAIN_LABEL_MD5)
114+
paddle.v2.dataset.common.download(TEST_IMAGE_URL, 'mnist', TEST_IMAGE_MD5)
115+
paddle.v2.dataset.common.download(TEST_LABEL_URL, 'mnist', TRAIN_LABEL_MD5)

python/paddle/v2/dataset/movielens.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ def unittest():
205205
print train_count, test_count
206206

207207

208-
def fetch_data():
209-
paddle.v2.dataset.common.download(URL, "movielens", MD5)
208+
def fetch():
209+
download(URL, "movielens", MD5)
210210

211211

212212
if __name__ == '__main__':

python/paddle/v2/dataset/sentiment.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import nltk
2727
from nltk.corpus import movie_reviews
2828

29-
import paddle.v2.dataset.common
29+
import common
3030

3131
__all__ = ['train', 'test', 'get_word_dict']
3232
NUM_TRAINING_INSTANCES = 1600
@@ -127,5 +127,5 @@ def test():
127127
return reader_creator(data_set[NUM_TRAINING_INSTANCES:])
128128

129129

130-
def fetch_data():
130+
def fetch():
131131
nltk.download('movie_reviews', download_dir=common.DATA_HOME)

python/paddle/v2/dataset/uci_housing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,5 @@ def reader():
9191
return reader
9292

9393

94-
def fetch_data():
95-
paddle.v2.dataset.common.download(URL, 'uci_housing', MD5)
94+
def fetch():
95+
download(URL, 'uci_housing', MD5)

python/paddle/v2/dataset/wmt14.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"""
1717
import tarfile
1818

19-
import paddle.v2.dataset.common
19+
from paddle.v2.dataset.common import download
2020

2121
__all__ = ['train', 'test', 'build_dict']
2222

@@ -95,15 +95,13 @@ def reader():
9595

9696
def train(dict_size):
9797
return reader_creator(
98-
paddle.v2.dataset.common.download(URL_TRAIN, 'wmt14', MD5_TRAIN),
99-
'train/train', dict_size)
98+
download(URL_TRAIN, 'wmt14', MD5_TRAIN), 'train/train', dict_size)
10099

101100

102101
def test(dict_size):
103102
return reader_creator(
104-
paddle.v2.dataset.common.download(URL_TRAIN, 'wmt14', MD5_TRAIN),
105-
'test/test', dict_size)
103+
download(URL_TRAIN, 'wmt14', MD5_TRAIN), 'test/test', dict_size)
106104

107105

108-
def fetch_data():
109-
paddle.v2.dataset.common.download(URL_TRAIN, 'wmt14', MD5_TRAIN)
106+
def fetch():
107+
download(URL_TRAIN, 'wmt14', MD5_TRAIN)

0 commit comments

Comments
 (0)