@@ -0,0 +1,1752 @@
+from pylearn2.utils import serial%0Aimport sys%0A_, model_path = sys.argv%0Amodel = serial.load(model_path)%0Aspace = model.generator.get_output_space()%0Afrom pylearn2.config import yaml_parse%0Afrom pylearn2.datasets import dense_design_matrix%0Afrom pylearn2.gui.patch_viewer import PatchViewer%0Aimport numpy as np%0A%0Adataset = yaml_parse.load(model.dataset_yaml_src)%0Aif dataset.view_converter is None:%0A    dataset.view_converter = dense_design_matrix.DefaultViewConverter((32, 32, 3), dataset.axes)%0A%0Arows = 4%0Asample_cols = 5%0A%0A# First sample conditional data%0A# TODO: Also try retrieving real conditional data%0Aconditional_data = model.generator.condition_distribution.sample(rows * sample_cols).eval()%0A%0A# For some reason format_as from VectorSpace is not working right%0Atopo_samples = model.generator.sample(conditional_data).eval()%0Asamples = dataset.get_design_matrix(topo_samples)%0Aprint 'Original shape:', samples.shape%0Adataset.view_converter.axes = %5B'b', 0, 1, 'c'%5D%0Atopo_samples = dataset.get_topological_view(samples)%0A%0Apv = PatchViewer(grid_shape=(rows, sample_cols + 1), patch_shape=(32,32),%0A                 is_color=True)%0Ascale = np.abs(samples).max()%0A%0AX = dataset.X%0Atopo = dataset.get_topological_view()%0Afor i in xrange(samples.shape%5B0%5D):%0A    topo_sample = topo_samples%5Bi, :, :, :%5D%0A    print topo_samples.shape, topo_sample.shape%0A    print topo_sample.min(), topo_sample.max(), topo_sample.shape%0A    pv.add_patch(topo_sample / scale, rescale=False)%0A%0A    if (i +1) %25 sample_cols == 0:%0A        sample = samples%5Bi, :%5D%0A        dists = np.square(X - sample).sum(axis=1)%0A        j = np.argmin(dists)%0A        match = topo%5Bj%5D%0A        print 'Nearest data point:', match.min(), match.max(), match.shape%0A        pv.add_patch(match, rescale=True, activation=1)%0A%0Apv.show()%0A

Add sampler for conditional LFW(crop)