@@ -0,0 +1,2817 @@
+package org.deeplearning4j.nn.transferlearning;%0A%0Aimport org.deeplearning4j.nn.conf.NeuralNetConfiguration;%0Aimport org.deeplearning4j.nn.conf.Updater;%0Aimport org.deeplearning4j.nn.conf.layers.DenseLayer;%0Aimport org.deeplearning4j.nn.layers.FrozenLayer;%0Aimport org.deeplearning4j.nn.multilayer.MultiLayerNetwork;%0Aimport org.deeplearning4j.util.ModelSerializer;%0Aimport org.junit.Test;%0Aimport org.nd4j.linalg.activations.Activation;%0Aimport org.nd4j.linalg.api.ndarray.INDArray;%0Aimport org.nd4j.linalg.lossfunctions.LossFunctions;%0A%0Aimport java.io.ByteArrayInputStream;%0Aimport java.io.ByteArrayOutputStream;%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0A%0Aimport static org.junit.Assert.assertFalse;%0Aimport static org.junit.Assert.assertTrue;%0A%0A/**%0A * Created by Alex on 10/07/2017.%0A */%0Apublic class TestTransferLearningModelSerializer %7B%0A%0A    @Test%0A    public void testModelSerializerFrozenLayers() throws Exception %7B%0A%0A        NeuralNetConfiguration.Builder overallConf = new NeuralNetConfiguration.Builder()%0A                .learningRate(0.1)%0A                .updater(Updater.SGD)%0A                .activation(Activation.TANH);%0A%0A        FineTuneConfiguration finetune = new FineTuneConfiguration.Builder().learningRate(0.1).build();%0A%0A        int nIn = 6;%0A        int nOut = 3;%0A%0A        MultiLayerNetwork origModel = new MultiLayerNetwork(overallConf.clone().list()%0A                .layer(0, new DenseLayer.Builder().nIn(6).nOut(5).build())%0A                .layer(1, new DenseLayer.Builder().nIn(5).nOut(4).build())%0A                .layer(2, new DenseLayer.Builder().nIn(4).nOut(3).build())%0A                .layer(3, new org.deeplearning4j.nn.conf.layers.OutputLayer.Builder(%0A                        LossFunctions.LossFunction.MCXENT).activation(Activation.SOFTMAX).nIn(3).nOut(3)%0A                        .build())%0A                .build());%0A        origModel.init();%0A%0A        MultiLayerNetwork withFrozen = new TransferLearning.Builder(origModel)%0A                .fineTuneConfiguration(finetune)%0A                .setFeatureExtractor(1)%0A                .build();%0A%0A        assertTrue(withFrozen.getLayer(0) instanceof FrozenLayer);%0A        assertTrue(withFrozen.getLayer(1) instanceof FrozenLayer);%0A%0A        ByteArrayOutputStream baos = new ByteArrayOutputStream();%0A        ModelSerializer.writeModel(withFrozen, baos, false);%0A        baos.close();%0A%0A        byte%5B%5D asBytes = baos.toByteArray();%0A%0A        ByteArrayInputStream bais = new ByteArrayInputStream(asBytes);%0A        MultiLayerNetwork restored = ModelSerializer.restoreMultiLayerNetwork(bais);%0A%0A        assertTrue(restored.getLayer(0) instanceof FrozenLayer);%0A        assertTrue(restored.getLayer(1) instanceof FrozenLayer);%0A        assertFalse(restored.getLayer(0) instanceof FrozenLayer);%0A        assertFalse(restored.getLayer(0) instanceof FrozenLayer);%0A%0A    %7D%0A%0A%7D%0A

Test for model serializer + frozen layers