def load_data(root_dir: Optional[str] = None) -> Tuple[PickleDataset, PickleDataset]:
"""Load and return the Street View House Numbers (SVHN) dataset.
Args:
root_dir: The path to store the downloaded data. When `path` is not provided, the data will be saved into
`fastestimator_data` under the user's home directory.
Returns:
(train_data, test_data)
"""
home = str(Path.home())
if root_dir is None:
root_dir = os.path.join(home, 'fastestimator_data', 'SVHN')
else:
root_dir = os.path.join(os.path.abspath(root_dir), 'SVHN')
os.makedirs(root_dir, exist_ok=True)
train_file_path = os.path.join(root_dir, 'train.pickle')
test_file_path = os.path.join(root_dir, 'test.pickle')
train_compressed_path = os.path.join(root_dir, "train.tar.gz")
test_compressed_path = os.path.join(root_dir, "test.tar.gz")
train_folder_path = os.path.join(root_dir, "train")
test_folder_path = os.path.join(root_dir, "test")
if not os.path.exists(train_folder_path):
# download
if not os.path.exists(train_compressed_path):
print("Downloading train data to {}".format(root_dir))
wget.download('http://ufldl.stanford.edu/housenumbers/train.tar.gz', root_dir, bar=bar_custom)
# extract
print("\nExtracting files ...")
with tarfile.open(train_compressed_path) as tar:
tar.extractall(root_dir)
if not os.path.exists(test_folder_path):
# download
if not os.path.exists(test_compressed_path):
print("Downloading eval data to {}".format(root_dir))
wget.download('http://ufldl.stanford.edu/housenumbers/test.tar.gz', root_dir, bar=bar_custom)
# extract
print("\nExtracting files ...")
with tarfile.open(test_compressed_path) as tar:
tar.extractall(root_dir)
# glob and generate bbox files
if not os.path.exists(train_file_path):
print("\nConstructing bounding box data ...")
_extract_metadata(train_folder_path, "train", train_file_path)
if not os.path.exists(test_file_path):
print("\nConstructing bounding box data ...")
_extract_metadata(test_folder_path, "test", test_file_path)
return PickleDataset(train_file_path), PickleDataset(test_file_path)