def download(self, local_dir_=None, url_=None):
'''
Args:
local_dir_: where to save downloaded file
url_: where to download dataset, if None, use default 'http://yann.lecun.com/exdb/mnist/'
'''
# TODO check whether file exists
if url_ is None:
url_ = 'http://yann.lecun.com/exdb/mnist/'
if local_dir_ is None:
local_dir = self.DEFAULT_DIR
else:
local_dir = Path(local_dir_)
local_dir.mkdir(parents=True, exist_ok=True)
in_filename = '%(subset)s-%(type_s)s-idx%(ndim)s-ubyte.gz'
for subset, (type_s, ndim) in product(
('train', 't10k'), zip(('images', 'labels'), (3,1))):
filename = in_filename % locals()
urllib.request.urlretrieve( url_ + filename, str(local_dir / filename))
评论列表
文章目录