Example #1
0
def pretrain_sae(X, hyper_params):
    """TODO: Docstring for pretrain_sae.

    :arg1: TODO
    :returns: TODO

    """
    params = []
    x = T.matrix()

    layer_input = X
    for idx, hidsize in enumerate(hyper_params['hidden_layers_sizes']):
        W, b = train_autoencode(layer_input, int(np.sqrt(hidsize)),
                                hyper_params['iter_nums'][idx],
                                hyper_params['alphas'][idx],
                                hyper_params['decays'][idx],
                                hyper_params['betas'][idx],
                                hyper_params['rhos'][idx])[:2]
        params.append((W, b))
        visualize_ae_image(W, 'sae_%d.png' % (idx), int(np.sqrt(W.get_value().shape[0])),
                           int(np.sqrt(W.get_value().shape[1])), process_grey)
        f = function(inputs=[x,], outputs=[ae_encode(x, W, b)], name='f')
        layer_input = f(layer_input)[0]

    return params, layer_input
Example #2
0
def sae_predict(X, weights):
    """TODO: Docstring for sae_predict.
    :returns: TODO

    """
    inp = T.matrix(name='inp')
    for idx, hp in enumerate(weights):
        if idx == 0:
            res = ae_encode(inp, hp[0], hp[1])
        elif idx != len(weights)-1:
            res = ae_encode(res, hp[0], hp[1])
        else:
            res = softmax_predict(res, hp[0], hp[1])

    f = function(inputs=[inp,], outputs=[res,], name='f')

    return f(X)[0]
Example #3
0
def sae_extract(x, weights):
    """TODO: Docstring for sae_extract.
    :returns: TODO

    """
    pred = x
    for hp in weights:
        pred = ae_encode(pred, hp[0], hp[1])

    return pred