예제 #1
0
def generate(params):
    dbn_params = dbn.stack_params(params)

    # 10 fantasies.
    # initial_pixels = np.zeros((10, 28**2))
    # initial_pixels = inputs[0:10]

    # Clamp the softmax units, one for each class.
    sample_v_softmax_clamped = functools.partial(sample_v_softmax,
                                                 labels=np.eye(10))

    # Perform an upward pass from the pixels to the visible units of
    # the top-level RBM.
    # initial_v = np.hstack((
    #         np.eye(10),
    #         up_pass(dbn_params, initial_pixels)))

    initial_v = np.hstack(
        (np.eye(10), np.random.random((10, dbn_params[-1].W.shape[1] - 10))))

    # Initialize the gibbs chain.
    gc = rbm.gibbs_chain(initial_v, dbn_params[-1], rbm.sample_h,
                         sample_v_softmax_clamped)

    tile_2_by_5 = functools.partial(utils.tile, grid_shape=(2, 5))

    gen = itertools.islice(gc, 1, None, 1)
    gen = itertools.islice(gen, 2000)
    gen = itertools.imap(operator.itemgetter(1), gen)
    gen = itertools.imap(lambda v: down_pass(dbn_params, v), gen)
    gen = itertools.imap(tile_2_by_5, gen)

    # Save to disk.
    utils.save_images(gen, tempfile.mkdtemp(dir=OUTPUT_PATH))
예제 #2
0
def generate(params, n=1, start=1, step=20, count=100):
    # Use the probability as pixel intensities.
    # This means we can't use the very first sample from the chain, as
    # it has v_mean == None.
    assert start > 0

    num_vis = params.W.shape[1]
    #initial_v = np.zeros((n, num_vis))
    initial_v = inputs[:n]
    #initial_v = np.random.random((n, num_vis))
    gc = rbm.gibbs_chain(initial_v, params, rbm.sample_h, rbm.sample_v)

    g = itertools.islice(gc, start, None, step)
    g = itertools.islice(g, count)
    g = itertools.imap(operator.itemgetter(1), g)
    g = itertools.imap(utils.tile, g)
    utils.save_images(g, tempfile.mkdtemp(dir=OUTPUT_PATH))
예제 #3
0
파일: mnist.py 프로젝트: aragornkishore/ml
def generate(params, n=1, start=1, step=20, count=100):
    # Use the probability as pixel intensities.
    # This means we can't use the very first sample from the chain, as
    # it has v_mean == None.
    assert start > 0

    num_vis = params.W.shape[1]
    #initial_v = np.zeros((n, num_vis))
    initial_v = inputs[:n]
    #initial_v = np.random.random((n, num_vis))
    gc = rbm.gibbs_chain(initial_v,
                         params,
                         rbm.sample_h,
                         rbm.sample_v)

    g = itertools.islice(gc, start, None, step)
    g = itertools.islice(g, count)
    g = itertools.imap(operator.itemgetter(1), g)
    g = itertools.imap(utils.tile, g)
    utils.save_images(g, tempfile.mkdtemp(dir=OUTPUT_PATH))
예제 #4
0
def generate(params):
    dbn_params = dbn.stack_params(params)

    # 10 fantasies.
    # initial_pixels = np.zeros((10, 28**2))
    # initial_pixels = inputs[0:10]

    # Clamp the softmax units, one for each class.
    sample_v_softmax_clamped = functools.partial(sample_v_softmax,
                                                 labels=np.eye(10))

    # Perform an upward pass from the pixels to the visible units of
    # the top-level RBM.
    # initial_v = np.hstack((
    #         np.eye(10),
    #         up_pass(dbn_params, initial_pixels)))

    initial_v = np.hstack((
            np.eye(10),
            np.random.random((10, dbn_params[-1].W.shape[1] - 10))))

    # Initialize the gibbs chain.
    gc = rbm.gibbs_chain(initial_v,
                         dbn_params[-1],
                         rbm.sample_h,
                         sample_v_softmax_clamped)

    tile_2_by_5 = functools.partial(utils.tile, grid_shape=(2, 5))

    gen = itertools.islice(gc, 1, None, 1)
    gen = itertools.islice(gen, 2000)
    gen = itertools.imap(operator.itemgetter(1), gen)
    gen = itertools.imap(lambda v: down_pass(dbn_params, v), gen)
    gen = itertools.imap(tile_2_by_5, gen)

    # Save to disk.
    utils.save_images(gen, tempfile.mkdtemp(dir=OUTPUT_PATH))