Example usage for org.deeplearning4j.nn.conf NeuralNetConfiguration.Builder NeuralNetConfiguration.Builder

List of usage examples for org.deeplearning4j.nn.conf NeuralNetConfiguration.Builder NeuralNetConfiguration.Builder

Introduction

In this page you can find the example usage for org.deeplearning4j.nn.conf NeuralNetConfiguration.Builder NeuralNetConfiguration.Builder.

Prototype

NeuralNetConfiguration.Builder

Source Link

Usage

From source file:org.eigengo.rsa.identity.v100.AlexNet.java

License:Open Source License

public MultiLayerConfiguration conf() {
    double nonZeroBias = 1;
    double dropOut = 0.5;
    SubsamplingLayer.PoolingType poolingType = SubsamplingLayer.PoolingType.MAX;

    // TODO split and link kernel maps on GPUs - 2nd, 4th, 5th convolution should only connect maps on the same gpu, 3rd connects to all in 2nd
    MultiLayerConfiguration.Builder conf = new NeuralNetConfiguration.Builder().seed(seed)
            .weightInit(WeightInit.DISTRIBUTION).dist(new NormalDistribution(0.0, 0.01)).activation("relu")
            .updater(Updater.NESTEROVS).iterations(iterations)
            .gradientNormalization(GradientNormalization.RenormalizeL2PerLayer) // normalize to prevent vanishing or exploding gradients
            .optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT).learningRate(1e-2)
            .biasLearningRate(1e-2 * 2).learningRateDecayPolicy(LearningRatePolicy.Step).lrPolicyDecayRate(0.1)
            .lrPolicySteps(100000).regularization(true).l2(5 * 1e-4).momentum(0.9).miniBatch(false).list()
            .layer(0,/*ww  w  .  j  av a2 s. com*/
                    new ConvolutionLayer.Builder(new int[] { 11, 11 }, new int[] { 4, 4 }, new int[] { 3, 3 })
                            .name("cnn1").nIn(channels).nOut(96).build())
            .layer(1, new LocalResponseNormalization.Builder().name("lrn1").build())
            .layer(2,
                    new SubsamplingLayer.Builder(poolingType, new int[] { 3, 3 }, new int[] { 2, 2 })
                            .name("maxpool1").build())
            .layer(3,
                    new ConvolutionLayer.Builder(new int[] { 5, 5 }, new int[] { 1, 1 }, new int[] { 2, 2 })
                            .name("cnn2").nOut(256).biasInit(nonZeroBias).build())
            .layer(4,
                    new LocalResponseNormalization.Builder().name("lrn2").k(2).n(5).alpha(1e-4).beta(0.75)
                            .build())
            .layer(5,
                    new SubsamplingLayer.Builder(poolingType, new int[] { 3, 3 }, new int[] { 2, 2 })
                            .name("maxpool2").build())
            .layer(6,
                    new ConvolutionLayer.Builder(new int[] { 3, 3 }, new int[] { 1, 1 }, new int[] { 1, 1 })
                            .name("cnn3").nOut(384).build())
            .layer(7,
                    new ConvolutionLayer.Builder(new int[] { 3, 3 }, new int[] { 1, 1 }, new int[] { 1, 1 })
                            .name("cnn4").nOut(384).biasInit(nonZeroBias).build())
            .layer(8,
                    new ConvolutionLayer.Builder(new int[] { 3, 3 }, new int[] { 1, 1 }, new int[] { 1, 1 })
                            .name("cnn5").nOut(256).biasInit(nonZeroBias).build())
            .layer(9,
                    new SubsamplingLayer.Builder(poolingType, new int[] { 3, 3 }, new int[] { 2, 2 })
                            .name("maxpool3").build())
            .layer(10,
                    new DenseLayer.Builder().name("ffn1").nOut(4096).dist(new GaussianDistribution(0, 0.005))
                            .biasInit(nonZeroBias).dropOut(dropOut).build())
            .layer(11,
                    new DenseLayer.Builder().name("ffn2").nOut(4096).dist(new GaussianDistribution(0, 0.005))
                            .biasInit(nonZeroBias).dropOut(dropOut).build())
            .layer(12,
                    new OutputLayer.Builder(LossFunctions.LossFunction.NEGATIVELOGLIKELIHOOD).name("output")
                            .nOut(numLabels).activation("softmax").build())
            .backprop(true).pretrain(false).cnnInputSize(height, width, channels);

    return conf.build();
}