Exemplo n.º 1
0
def main():
    xtrain, xtest = mnist_data()

    output_path = 'output/vae'
    epochs = 100
    batches = 10000
    batch_size = 128
    test_batches = 5000

    z_k = 30
    srng = RandomStreams(123)
    input_units = 28 * 28
    opt = Adam(1e-3)
    regularizer = l2(1e-5)
    encoder_net = Stack([
        DenseLayer(input_units, 512),
        ActivationLayer(leaky_relu),
        DenseLayer(512, 256),
        ActivationLayer(leaky_relu),
        DenseLayer(256, z_k * 2)
    ])
    decoder_net = Stack([
        DenseLayer(z_k, 256),
        ActivationLayer(leaky_relu),
        DenseLayer(256, 512),
        ActivationLayer(leaky_relu),
        DenseLayer(512, input_units)
    ])

    model = VAE(z_k=z_k,
                opt=opt,
                encoder_net=encoder_net,
                decoder_net=decoder_net,
                regularizer=regularizer,
                srng=srng)
    model.train(output_path=output_path,
                epochs=epochs,
                batches=batches,
                batch_size=batch_size,
                test_batches=test_batches,
                xtrain=xtrain,
                xtest=xtest)
def main():
    xtrain, xtest = mnist_data()

    output_path = 'output/reinforce_autoencoder'
    epochs = 1000
    batches = 10000
    batch_size = 64
    test_batches = 5000

    z_n = 30
    z_k = 10
    srng = RandomStreams(123)
    input_units = 28 * 28
    opt = Adam(3e-4)
    regularizer = l2(1e-4)
    entropy_weight = 1e-2
    units = 512
    dropout = 0.
    encoder_net = Stack([
        DenseLayer(input_units, units),
        # BNLayer(512),
        ActivationLayer(activation),
        DropoutLayer(dropout, srng=srng),
        DenseLayer(units, units),
        # BNLayer(256),
        ActivationLayer(activation),
        DropoutLayer(dropout, srng=srng),
        DenseLayer(units, units),
        # BNLayer(256),
        ActivationLayer(activation),
        DropoutLayer(dropout, srng=srng),
        DenseLayer(units, z_n * z_k)
    ])
    decoder_net = Stack([
        DenseLayer(z_n * z_k, units),
        # BNLayer(256),
        ActivationLayer(activation),
        DropoutLayer(dropout, srng=srng),
        DenseLayer(units, units),
        # BNLayer(512),
        ActivationLayer(activation),
        DropoutLayer(dropout, srng=srng),
        DenseLayer(units, units),
        # BNLayer(256),
        ActivationLayer(activation),
        DropoutLayer(dropout, srng=srng),
        DenseLayer(units, input_units)
    ])

    model = ReinforceAutoencoder(z_n=z_n,
                                 z_k=z_k,
                                 opt=opt,
                                 encoder_net=encoder_net,
                                 decoder_net=decoder_net,
                                 regularizer=regularizer,
                                 entropy_weight=entropy_weight,
                                 srng=srng)
    model.train(output_path=output_path,
                epochs=epochs,
                batches=batches,
                batch_size=batch_size,
                test_batches=test_batches,
                xtrain=xtrain,
                xtest=xtest)
def main():
    xtrain, xtest = mnist_data()

    output_path = 'output/gumbel_autoencoder_iw'
    epochs = 1000
    batches = 10000
    batch_size = 128
    test_batches = 5000

    z_n = 20
    z_k = 10
    srng = RandomStreams(123)
    tau0 = 1.
    tau_decay = 3e-6
    tau_min = 0.1
    input_units = 28 * 28
    hard = False
    opt = Adam(3e-4)
    regularizer = l2(1e-5)
    kl_weight = 1e-3
    units = 512
    pz_units = 512
    pz_rate = 1e-2
    recurrent_pz = False
    dropout = 0.
    iw = True
    encoder_net = Stack([
        DenseLayer(input_units, units),
        BNLayer(units),
        ActivationLayer(activation),
        DropoutLayer(dropout, srng=srng),
        DenseLayer(units, units),
        BNLayer(units),
        ActivationLayer(activation),
        DropoutLayer(dropout, srng=srng),
        DenseLayer(units, z_n * z_k)
    ])
    decoder_net = Stack([
        DenseLayer(z_n * z_k, units),
        BNLayer(units),
        ActivationLayer(activation),
        DropoutLayer(dropout, srng=srng),
        DenseLayer(units, units),
        BNLayer(units),
        ActivationLayer(activation),
        DropoutLayer(dropout, srng=srng),
        DenseLayer(units, input_units)
    ])

    model = GumbelAutoencoder(z_n=z_n,
                              z_k=z_k,
                              opt=opt,
                              encoder_net=encoder_net,
                              decoder_net=decoder_net,
                              regularizer=regularizer,
                              srng=srng,
                              pz_units=pz_units,
                              pz_rate=pz_rate,
                              recurrent_pz=recurrent_pz,
                              tau0=tau0,
                              tau_min=tau_min,
                              tau_decay=tau_decay,
                              kl_weight=kl_weight,
                              iw=iw,
                              hard=hard)
    model.train(output_path=output_path,
                epochs=epochs,
                batches=batches,
                batch_size=batch_size,
                test_batches=test_batches,
                xtrain=xtrain,
                xtest=xtest)
Exemplo n.º 4
0
def main():
    xtrain, xtest = mnist_data()

    output_path = 'output/gumbel_quantized_autoencoder_iw'
    epochs = 1000
    batches = 5000
    batch_size = 128
    test_batches = 5000

    learn_pz = False
    z_n = 30
    z_k = 5
    srng = RandomStreams(123)
    tau0 = 1.
    tau_decay = 1e-5
    tau_min = 0.1
    input_units = 28 * 28
    hard = False
    opt = Adam(1e-3)
    regularizer = l2(1e-5)
    units = 256
    iw = True
    iw_samples = 20
    val_iw = True
    val_iw_samples = 100
    encoder_net = Stack([
        DenseLayer(input_units, units),
        ActivationLayer(leaky_relu),
        DenseLayer(units, units),
        ActivationLayer(leaky_relu),
        DenseLayer(units, z_n * z_k)
    ])
    decoder_net = Stack([
        DenseLayer(z_n, units),
        ActivationLayer(leaky_relu),
        DenseLayer(units, units),
        ActivationLayer(leaky_relu),
        DenseLayer(units, input_units)
    ])

    model = GumbelQuantizedAutoencoder(z_n=z_n,
                                       z_k=z_k,
                                       opt=opt,
                                       encoder_net=encoder_net,
                                       decoder_net=decoder_net,
                                       regularizer=regularizer,
                                       srng=srng,
                                       tau0=tau0,
                                       tau_min=tau_min,
                                       tau_decay=tau_decay,
                                       learn_pz=learn_pz,
                                       iw=iw,
                                       iw_samples=iw_samples,
                                       val_iw=val_iw,
                                       val_iw_samples=val_iw_samples,
                                       hard=hard)
    model.train(output_path=output_path,
                epochs=epochs,
                batches=batches,
                batch_size=batch_size,
                test_batches=test_batches,
                xtrain=xtrain,
                xtest=xtest)
def main():
    xtrain, xtest = mnist_data()

    output_path = 'output/gumbel_autoencoder'
    epochs = 1000
    batches = 10000
    batch_size = 128
    test_batches = 5000

    learn_pz = False
    use_mean = False
    z_n = 30
    z_k = 10
    srng = RandomStreams(123)
    tau0 = 1.
    tau_decay = 1e-5
    tau_min = 0.1
    input_units = 28 * 28
    hard = False
    opt = Adam(1e-3)
    regularizer = l2(1e-5)
    units = 1024
    dropout = 0.5
    encoder_net = Stack([
        DenseLayer(input_units, units),
        ActivationLayer(activation),
        BNLayer(units),
        DropoutLayer(dropout, srng=srng),
        DenseLayer(units, units),
        ActivationLayer(activation),
        BNLayer(units),
        DropoutLayer(dropout, srng=srng),
        DenseLayer(units, units),
        ActivationLayer(activation),
        BNLayer(units),
        DropoutLayer(dropout, srng=srng),
        DenseLayer(units, z_n * z_k)
    ])
    decoder_net = Stack([
        DenseLayer(z_n * z_k, units),
        ActivationLayer(activation),
        BNLayer(units),
        DropoutLayer(dropout, srng=srng),
        DenseLayer(units, units),
        ActivationLayer(activation),
        BNLayer(units),
        DropoutLayer(dropout, srng=srng),
        DenseLayer(units, units),
        ActivationLayer(activation),
        BNLayer(units),
        DropoutLayer(dropout, srng=srng),
        DenseLayer(units, input_units)
    ])

    model = GumbelAutoencoder(z_n=z_n,
                              z_k=z_k,
                              opt=opt,
                              encoder_net=encoder_net,
                              decoder_net=decoder_net,
                              regularizer=regularizer,
                              srng=srng,
                              tau0=tau0,
                              tau_min=tau_min,
                              tau_decay=tau_decay,
                              learn_pz=learn_pz,
                              use_mean=use_mean,
                              hard=hard)
    model.train(output_path=output_path,
                epochs=epochs,
                batches=batches,
                batch_size=batch_size,
                test_batches=test_batches,
                xtrain=xtrain,
                xtest=xtest)