def load_data(root_dir: Optional[str] = None) -> Tuple[LabeledDirDataset, LabeledDirDataset]:
"""Load and return the USPS 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', 'USPS')
else:
root_dir = os.path.join(os.path.abspath(root_dir), 'USPS')
os.makedirs(root_dir, exist_ok=True)
# download data to memory
train_compressed_path = os.path.join(root_dir, "zip.train.gz")
test_compressed_path = os.path.join(root_dir, "zip.test.gz")
train_base_path = os.path.join(root_dir, "train")
test_base_path = os.path.join(root_dir, "test")
if not os.path.exists(train_base_path):
print("Downloading train data to {}".format(root_dir))
download_file_from_google_drive("1NlaCnlhV-PA_Rek8w8eQqJUeYCZJ0olG", train_compressed_path)
train_images, train_labels = _extract_images_labels(train_compressed_path)
_write_data(train_images, train_labels, train_base_path, "train")
if not os.path.exists(test_base_path):
print("Downloading test data to {}".format(root_dir))
download_file_from_google_drive("1lagM-V1nmAdS3Uz9Uk4bB9cKqE_agt59", test_compressed_path)
test_images, test_labels = _extract_images_labels(test_compressed_path)
_write_data(test_images, test_labels, test_base_path, "test")
# make datasets
return LabeledDirDataset(train_base_path, file_extension=".png"), LabeledDirDataset(test_base_path,
file_extension=".png")