def run_autoencoder(): imfiles = glob.glob('cropped/*.pgm') X = np.vstack([np.array(Image.open(fname).convert('L')).flatten() for fname in imfiles]) # digits = datasets.load_digits() # X = np.asarray(digits.data, 'float32') rbm = train_rbm(X, n_components=100, n_iter=5) images = [comp.reshape(192, 168) for comp in rbm.components_] images = images[:10] hlp.smartshow(images)
def run_autoencoder(): imfiles = glob.glob('cropped/*.pgm') X = np.vstack([ np.array(Image.open(fname).convert('L')).flatten() for fname in imfiles ]) # digits = datasets.load_digits() # X = np.asarray(digits.data, 'float32') rbm = train_rbm(X, n_components=100, n_iter=5) images = [comp.reshape(192, 168) for comp in rbm.components_] images = images[:10] hlp.smartshow(images)
def run_auto(): X = load_data('gender/male') X = X.astype(np.float32) / 256 rbm = BernoulliRBM(random_state=0, verbose=True) rbm.learning_rate = 0.06 rbm.n_iter = 20 rbm.n_components = 2000 rbm.fit(X) cimgs = [comp.reshape(100, 100) for comp in rbm.components_] smartshow(cimgs[:12]) return rbm
def run_deep(): X = load_data('gender/male') X = X.astype(np.float32) / 256 rbm1 = BernoulliRBM(n_components=10000, n_iter=20, learning_rate=0.05, random_state=0, verbose=True) rbm2 = BernoulliRBM(n_components=200, n_iter=20, learning_rate=0.05, random_state=0, verbose=True) model = Pipeline(steps=[('rbm1', rbm1), ('rbm2', rbm)]) model.fit(X) cimgs = [comp.reshape(100, 100) for comp in model.steps[1][1].components_] smartshow(cimgs[:12]) return model