MCPcopy Index your code
hub / github.com/tensorlayer/TensorLayer / load_cropped_svhn

Function load_cropped_svhn

tensorlayer/files/utils.py:646–740  ·  view source on GitHub ↗

Load Cropped SVHN. The Cropped Street View House Numbers (SVHN) Dataset contains 32x32x3 RGB images. Digit '1' has label 1, '9' has label 9 and '0' has label 0 (the original dataset uses 10 to represent '0'), see `ufldl website `__. Parameters

(path='data', include_extra=True)

Source from the content-addressed store, hash-verified

644
645
646def load_cropped_svhn(path='data', include_extra=True):
647 """Load Cropped SVHN.
648
649 The Cropped Street View House Numbers (SVHN) Dataset contains 32x32x3 RGB images.
650 Digit '1' has label 1, '9' has label 9 and '0' has label 0 (the original dataset uses 10 to represent '0'), see `ufldl website <http://ufldl.stanford.edu/housenumbers/>`__.
651
652 Parameters
653 ----------
654 path : str
655 The path that the data is downloaded to.
656 include_extra : boolean
657 If True (default), add extra images to the training set.
658
659 Returns
660 -------
661 X_train, y_train, X_test, y_test: tuple
662 Return splitted training/test set respectively.
663
664 Examples
665 ---------
666 >>> X_train, y_train, X_test, y_test = tl.files.load_cropped_svhn(include_extra=False)
667 >>> tl.vis.save_images(X_train[0:100], [10, 10], 'svhn.png')
668
669 """
670 start_time = time.time()
671
672 path = os.path.join(path, 'cropped_svhn')
673 logging.info("Load or Download Cropped SVHN > {} | include extra images: {}".format(path, include_extra))
674 url = "http://ufldl.stanford.edu/housenumbers/"
675
676 np_file = os.path.join(path, "train_32x32.npz")
677 if file_exists(np_file) is False:
678 filename = "train_32x32.mat"
679 filepath = maybe_download_and_extract(filename, path, url)
680 mat = sio.loadmat(filepath)
681 X_train = mat['X'] / 255.0 # to [0, 1]
682 X_train = np.transpose(X_train, (3, 0, 1, 2))
683 y_train = np.squeeze(mat['y'], axis=1)
684 y_train[y_train == 10] = 0 # replace 10 to 0
685 np.savez(np_file, X=X_train, y=y_train)
686 del_file(filepath)
687 else:
688 v = np.load(np_file, allow_pickle=True)
689 X_train = v['X']
690 y_train = v['y']
691 logging.info(" n_train: {}".format(len(y_train)))
692
693 np_file = os.path.join(path, "test_32x32.npz")
694 if file_exists(np_file) is False:
695 filename = "test_32x32.mat"
696 filepath = maybe_download_and_extract(filename, path, url)
697 mat = sio.loadmat(filepath)
698 X_test = mat['X'] / 255.0
699 X_test = np.transpose(X_test, (3, 0, 1, 2))
700 y_test = np.squeeze(mat['y'], axis=1)
701 y_test[y_test == 10] = 0
702 np.savez(np_file, X=X_test, y=y_test)
703 del_file(filepath)

Callers

nothing calls this directly

Calls 4

file_existsFunction · 0.85
del_fileFunction · 0.85
loadMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…