Created
          May 11, 2015 21:49 
        
      - 
      
- 
        Save agibsonccc/7f7b68403eafb5e912f1 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | Nd4j.ENFORCE_NUMERICAL_STABILITY = true; | |
| LayerFactory layerFactory = LayerFactories.getFactory(ConvolutionDownSampleLayer.class); | |
| int batchSize = 1000; | |
| /** | |
| * | |
| */ | |
| Nd4j.MAX_ELEMENTS_PER_SLICE = Integer.MAX_VALUE; | |
| Nd4j.MAX_ELEMENTS_PER_SLICE = Integer.MAX_VALUE; | |
| MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder() | |
| .optimizationAlgo(OptimizationAlgorithm.LBFGS).momentum(0.9) | |
| .dist(Nd4j.getDistributions().createUniform(1e-5, 1e-1)).constrainGradientToUnitNorm(true) | |
| .iterations(10).iterationListener(new ScoreIterationListener(1)).convolutionType(ConvolutionDownSampleLayer.ConvolutionType.MAX) | |
| .activationFunction("relu").filterSize(5, 1, 2, 2) | |
| .nIn(numRows * numColumns).nOut(2).batchSize(batchSize) | |
| .layerFactory(layerFactory) | |
| .list(2) | |
| .inputPreProcessor(0, new ConvolutionInputPreProcessor(28, 28)) | |
| .preProcessor(0, new ConvolutionPostProcessor()) | |
| .hiddenLayerSizes(new int[]{841}) | |
| .override(0, new ConfOverride() { | |
| @Override | |
| public void overrideLayer(int i, NeuralNetConfiguration.Builder builder) { | |
| if (i == 0) | |
| builder.filterSize(5, 1, 2, 2); | |
| } | |
| }) | |
| .override(1, new ConfOverride() { | |
| @Override | |
| public void overrideLayer(int i, NeuralNetConfiguration.Builder builder) { | |
| if (i == 1) { | |
| builder.activationFunction("softmax"); | |
| builder.weightInit(WeightInit.ZERO); | |
| builder.layerFactory(LayerFactories.getFactory(OutputLayer.class)); | |
| builder.lossFunction(LossFunctions.LossFunction.MCXENT); | |
| } | |
| } | |
| }).build(); | |
| MultiLayerNetwork network = new MultiLayerNetwork(conf); | |
| while(iter.hasNext()) { | |
| DataSet next = iter.next(); | |
| next.normalizeZeroMeanZeroUnitVariance(); | |
| network.fit(next); | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment