@Test
  public void testJson() throws Exception {
    MultiLayerConfiguration conf =
        new NeuralNetConfiguration.Builder()
            .list()
            .layer(0, new RBM.Builder().dist(new NormalDistribution(1, 1e-1)).build())
            .inputPreProcessor(0, new ReshapePreProcessor())
            .build();

    String json = conf.toJson();
    MultiLayerConfiguration from = MultiLayerConfiguration.fromJson(json);
    assertEquals(conf.getConf(0), from.getConf(0));

    Properties props = new Properties();
    props.put("json", json);
    String key = props.getProperty("json");
    assertEquals(json, key);
    File f = new File("props");
    f.deleteOnExit();
    BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(f));
    props.store(bos, "");
    bos.flush();
    bos.close();
    BufferedInputStream bis = new BufferedInputStream(new FileInputStream(f));
    Properties props2 = new Properties();
    props2.load(bis);
    bis.close();
    assertEquals(props2.getProperty("json"), props.getProperty("json"));
    String json2 = props2.getProperty("json");
    MultiLayerConfiguration conf3 = MultiLayerConfiguration.fromJson(json2);
    assertEquals(conf.getConf(0), conf3.getConf(0));
  }
  @Test
  public void testConvnetJson() {
    final int numRows = 75;
    final int numColumns = 75;
    int nChannels = 3;
    int outputNum = 6;
    int batchSize = 500;
    int iterations = 10;
    int seed = 123;

    // setup the network
    MultiLayerConfiguration.Builder builder =
        new NeuralNetConfiguration.Builder()
            .seed(seed)
            .iterations(iterations)
            .regularization(true)
            .l1(1e-1)
            .l2(2e-4)
            .useDropConnect(true)
            .dropOut(0.5)
            .miniBatch(true)
            .optimizationAlgo(OptimizationAlgorithm.CONJUGATE_GRADIENT)
            .list()
            .layer(
                0,
                new ConvolutionLayer.Builder(5, 5)
                    .nOut(5)
                    .dropOut(0.5)
                    .weightInit(WeightInit.XAVIER)
                    .activation("relu")
                    .build())
            .layer(
                1,
                new SubsamplingLayer.Builder(SubsamplingLayer.PoolingType.MAX, new int[] {2, 2})
                    .build())
            .layer(
                2,
                new ConvolutionLayer.Builder(3, 3)
                    .nOut(10)
                    .dropOut(0.5)
                    .weightInit(WeightInit.XAVIER)
                    .activation("relu")
                    .build())
            .layer(
                3,
                new SubsamplingLayer.Builder(SubsamplingLayer.PoolingType.MAX, new int[] {2, 2})
                    .build())
            .layer(4, new DenseLayer.Builder().nOut(100).activation("relu").build())
            .layer(
                5,
                new OutputLayer.Builder(LossFunctions.LossFunction.NEGATIVELOGLIKELIHOOD)
                    .nOut(outputNum)
                    .weightInit(WeightInit.XAVIER)
                    .activation("softmax")
                    .build())
            .backprop(true)
            .pretrain(false);

    new ConvolutionLayerSetup(builder, numRows, numColumns, nChannels);
    MultiLayerConfiguration conf = builder.build();
    String json = conf.toJson();
    MultiLayerConfiguration conf2 = MultiLayerConfiguration.fromJson(json);
    assertEquals(conf, conf2);
  }