コード例 #1
0
ファイル: sae.py プロジェクト: ShiehShieh/UFLDL-Solution
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
コード例 #2
0
ファイル: sae.py プロジェクト: ShiehShieh/UFLDL-Solution
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]
コード例 #3
0
ファイル: sae.py プロジェクト: ShiehShieh/UFLDL-Solution
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