Last active
November 13, 2020 11:48
-
-
Save obeshor/c9aad4aa9b5a0e113f080d280035e3d7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from urllib.request import urlretrieve | |
from os.path import isfile, isdir | |
from tqdm import tqdm | |
!mkdir data | |
data_dir = 'data/' | |
if not isdir(data_dir): | |
raise Exception("Data directory doesn't exist!") | |
class DLProgress(tqdm): | |
last_block = 0 | |
def hook(self, block_num=1, block_size=1, total_size=None): | |
self.total = total_size | |
self.update((block_num - self.last_block) * block_size) | |
self.last_block = block_num | |
if not isfile(data_dir + "train_32x32.mat"): | |
with DLProgress(unit='B', unit_scale=True, miniters=1, desc='SVHN Training Set') as pbar: | |
urlretrieve( | |
'http://ufldl.stanford.edu/housenumbers/train_32x32.mat', | |
data_dir + 'train_32x32.mat', | |
pbar.hook) | |
if not isfile(data_dir + "test_32x32.mat"): | |
with DLProgress(unit='B', unit_scale=True, miniters=1, desc='SVHN Testing Set') as pbar: | |
urlretrieve( | |
'http://ufldl.stanford.edu/housenumbers/test_32x32.mat', | |
data_dir + 'test_32x32.mat', | |
pbar.hook) | |
trainset = loadmat(data_dir + 'train_32x32.mat') | |
testset = loadmat(data_dir + 'test_32x32.mat') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment