def _load_mnist_dataset(shape, path, name='<STR_LIT>', url='<STR_LIT>'):
path = os.path.join(path, name)<EOL>def load_mnist_images(path, filename):<EOL><INDENT>filepath = maybe_download_and_extract(filename, path, url)<EOL>logging.info(filepath)<EOL>with gzip.open(filepath, '<STR_LIT:rb>') as f:<EOL><INDENT>data = np.frombuffer(f.read(), np.uint8, offset=<NUM_LIT:16>)<EOL><DEDENT>data = data.reshape(shape)<EOL>return data / np.float32(<NUM_LIT>)<EOL><DEDENT>def load_mnist_labels(path, filename):<EOL><INDENT>filepath = maybe_download_and_extract(filename, path, url)<EOL>with gzip.open(filepath, '<STR_LIT:rb>') as f:<EOL><INDENT>data = np.frombuffer(f.read(), np.uint8, offset=<NUM_LIT:8>)<EOL><DEDENT>return data<EOL><DEDENT>logging.info("<STR_LIT>".format(name.upper(), path))<EOL>X_train = load_mnist_images(path, '<STR_LIT>')<EOL>y_train = load_mnist_labels(path, '<STR_LIT>')<EOL>X_test = load_mnist_images(path, '<STR_LIT>')<EOL>y_test = load_mnist_labels(path, '<STR_LIT>')<EOL>X_train, X_val = X_train[:-<NUM_LIT>], X_train[-<NUM_LIT>:]<EOL>y_train, y_val = y_train[:-<NUM_LIT>], y_train[-<NUM_LIT>:]<EOL>X_train = np.asarray(X_train, dtype=np.float32)<EOL>y_train = np.asarray(y_train, dtype=np.int32)<EOL>X_val = np.asarray(X_val, dtype=np.float32)<EOL>y_val = np.asarray(y_val, dtype=np.int32)<EOL>X_test = np.asarray(X_test, dtype=np.float32)<EOL>y_test = np.asarray(y_test, dtype=np.int32)<EOL>return X_train, y_train, X_val, y_val, X_test, y_test<EOL>
A generic function to load mnist-like dataset.

    Parameters:
    ----------
    shape : tuple
        The shape of digit images.
    path : str
        The path that the data is downloaded to.
    name : str
        The dataset name you want to use(the default is 'mnist').
    url : str
        The url of dataset(the default is 'http://yann.lecun.com/exdb/mnist/').