Search in sources :

Example 1 with RBM

use of org.deeplearning4j.nn.conf.layers.RBM in project deeplearning4j by deeplearning4j.

the class ModelSerializer method taskByModel.

/**
     *
     * @param model
     * @return
     */
public static Task taskByModel(Model model) {
    Task task = new Task();
    try {
        task.setArchitectureType(Task.ArchitectureType.RECURRENT);
        if (model instanceof ComputationGraph) {
            task.setNetworkType(Task.NetworkType.ComputationalGraph);
            ComputationGraph network = (ComputationGraph) model;
            try {
                if (network.getLayers() != null && network.getLayers().length > 0) {
                    for (Layer layer : network.getLayers()) {
                        if (layer instanceof RBM || layer instanceof org.deeplearning4j.nn.layers.feedforward.rbm.RBM) {
                            task.setArchitectureType(Task.ArchitectureType.RBM);
                            break;
                        }
                        if (layer.type().equals(Layer.Type.CONVOLUTIONAL)) {
                            task.setArchitectureType(Task.ArchitectureType.CONVOLUTION);
                            break;
                        } else if (layer.type().equals(Layer.Type.RECURRENT) || layer.type().equals(Layer.Type.RECURSIVE)) {
                            task.setArchitectureType(Task.ArchitectureType.RECURRENT);
                            break;
                        }
                    }
                } else
                    task.setArchitectureType(Task.ArchitectureType.UNKNOWN);
            } catch (Exception e) {
            // do nothing here
            }
        } else if (model instanceof MultiLayerNetwork) {
            task.setNetworkType(Task.NetworkType.MultilayerNetwork);
            MultiLayerNetwork network = (MultiLayerNetwork) model;
            try {
                if (network.getLayers() != null && network.getLayers().length > 0) {
                    for (Layer layer : network.getLayers()) {
                        if (layer instanceof RBM || layer instanceof org.deeplearning4j.nn.layers.feedforward.rbm.RBM) {
                            task.setArchitectureType(Task.ArchitectureType.RBM);
                            break;
                        }
                        if (layer.type().equals(Layer.Type.CONVOLUTIONAL)) {
                            task.setArchitectureType(Task.ArchitectureType.CONVOLUTION);
                            break;
                        } else if (layer.type().equals(Layer.Type.RECURRENT) || layer.type().equals(Layer.Type.RECURSIVE)) {
                            task.setArchitectureType(Task.ArchitectureType.RECURRENT);
                            break;
                        }
                    }
                } else
                    task.setArchitectureType(Task.ArchitectureType.UNKNOWN);
            } catch (Exception e) {
            // do nothing here
            }
        }
        return task;
    } catch (Exception e) {
        task.setArchitectureType(Task.ArchitectureType.UNKNOWN);
        task.setNetworkType(Task.NetworkType.DenseNetwork);
        return task;
    }
}
Also used : Task(org.nd4j.linalg.heartbeat.reports.Task) Layer(org.deeplearning4j.nn.api.Layer) ComputationGraph(org.deeplearning4j.nn.graph.ComputationGraph) RBM(org.deeplearning4j.nn.conf.layers.RBM) MultiLayerNetwork(org.deeplearning4j.nn.multilayer.MultiLayerNetwork)

Example 2 with RBM

use of org.deeplearning4j.nn.conf.layers.RBM in project deeplearning4j by deeplearning4j.

the class NeuralNetConfigurationTest method getRBMConfig.

private static NeuralNetConfiguration getRBMConfig(int nIn, int nOut, WeightInit weightInit, boolean pretrain) {
    RBM layer = new RBM.Builder().nIn(nIn).nOut(nOut).weightInit(weightInit).dist(new NormalDistribution(1, 1)).visibleUnit(RBM.VisibleUnit.GAUSSIAN).hiddenUnit(RBM.HiddenUnit.RECTIFIED).activation(Activation.TANH).lossFunction(LossFunctions.LossFunction.KL_DIVERGENCE).build();
    NeuralNetConfiguration conf = new NeuralNetConfiguration.Builder().iterations(3).optimizationAlgo(OptimizationAlgorithm.CONJUGATE_GRADIENT).regularization(false).layer(layer).build();
    conf.setPretrain(pretrain);
    return conf;
}
Also used : NormalDistribution(org.deeplearning4j.nn.conf.distribution.NormalDistribution) RBM(org.deeplearning4j.nn.conf.layers.RBM)

Example 3 with RBM

use of org.deeplearning4j.nn.conf.layers.RBM in project deeplearning4j by deeplearning4j.

the class NeuralNetConfigurationTest method testRNG.

@Test
public void testRNG() {
    RBM layer = new RBM.Builder().nIn(trainingSet.numInputs()).nOut(trainingSet.numOutcomes()).weightInit(WeightInit.UNIFORM).visibleUnit(RBM.VisibleUnit.GAUSSIAN).hiddenUnit(RBM.HiddenUnit.RECTIFIED).activation(Activation.TANH).lossFunction(LossFunctions.LossFunction.RMSE_XENT).build();
    NeuralNetConfiguration conf = new NeuralNetConfiguration.Builder().seed(123).iterations(3).optimizationAlgo(OptimizationAlgorithm.CONJUGATE_GRADIENT).layer(layer).build();
    int numParams = conf.getLayer().initializer().numParams(conf);
    INDArray params = Nd4j.create(1, numParams);
    Layer model = conf.getLayer().instantiate(conf, null, 0, params, true);
    INDArray modelWeights = model.getParam(DefaultParamInitializer.WEIGHT_KEY);
    RBM layer2 = new RBM.Builder().nIn(trainingSet.numInputs()).nOut(trainingSet.numOutcomes()).weightInit(WeightInit.UNIFORM).visibleUnit(RBM.VisibleUnit.GAUSSIAN).hiddenUnit(RBM.HiddenUnit.RECTIFIED).activation(Activation.TANH).lossFunction(LossFunctions.LossFunction.RMSE_XENT).build();
    NeuralNetConfiguration conf2 = new NeuralNetConfiguration.Builder().seed(123).iterations(3).optimizationAlgo(OptimizationAlgorithm.CONJUGATE_GRADIENT).layer(layer2).build();
    int numParams2 = conf2.getLayer().initializer().numParams(conf);
    INDArray params2 = Nd4j.create(1, numParams);
    Layer model2 = conf2.getLayer().instantiate(conf2, null, 0, params2, true);
    INDArray modelWeights2 = model2.getParam(DefaultParamInitializer.WEIGHT_KEY);
    assertEquals(modelWeights, modelWeights2);
}
Also used : INDArray(org.nd4j.linalg.api.ndarray.INDArray) RBM(org.deeplearning4j.nn.conf.layers.RBM) Layer(org.deeplearning4j.nn.api.Layer) OutputLayer(org.deeplearning4j.nn.conf.layers.OutputLayer) DenseLayer(org.deeplearning4j.nn.conf.layers.DenseLayer) Test(org.junit.Test)

Example 4 with RBM

use of org.deeplearning4j.nn.conf.layers.RBM in project deeplearning4j by deeplearning4j.

the class TestPlayUI method testUI_RBM.

@Test
@Ignore
public void testUI_RBM() throws Exception {
    //RBM - for unsupervised layerwise pretraining
    StatsStorage ss = new InMemoryStatsStorage();
    UIServer uiServer = UIServer.getInstance();
    uiServer.attach(ss);
    MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT).iterations(1).learningRate(1e-5).list().layer(0, new RBM.Builder().nIn(4).nOut(3).build()).layer(1, new RBM.Builder().nIn(3).nOut(3).build()).layer(2, new OutputLayer.Builder().nIn(3).nOut(3).build()).pretrain(true).backprop(true).build();
    MultiLayerNetwork net = new MultiLayerNetwork(conf);
    net.init();
    net.setListeners(new StatsListener(ss), new ScoreIterationListener(1));
    DataSetIterator iter = new IrisDataSetIterator(150, 150);
    for (int i = 0; i < 50; i++) {
        net.fit(iter);
        Thread.sleep(100);
    }
    Thread.sleep(100000);
}
Also used : OutputLayer(org.deeplearning4j.nn.conf.layers.OutputLayer) InMemoryStatsStorage(org.deeplearning4j.ui.storage.InMemoryStatsStorage) StatsStorage(org.deeplearning4j.api.storage.StatsStorage) IrisDataSetIterator(org.deeplearning4j.datasets.iterator.impl.IrisDataSetIterator) UIServer(org.deeplearning4j.ui.api.UIServer) StatsListener(org.deeplearning4j.ui.stats.StatsListener) InMemoryStatsStorage(org.deeplearning4j.ui.storage.InMemoryStatsStorage) MultiLayerConfiguration(org.deeplearning4j.nn.conf.MultiLayerConfiguration) RBM(org.deeplearning4j.nn.conf.layers.RBM) MultiLayerNetwork(org.deeplearning4j.nn.multilayer.MultiLayerNetwork) ScoreIterationListener(org.deeplearning4j.optimize.listeners.ScoreIterationListener) IrisDataSetIterator(org.deeplearning4j.datasets.iterator.impl.IrisDataSetIterator) DataSetIterator(org.nd4j.linalg.dataset.api.iterator.DataSetIterator) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

RBM (org.deeplearning4j.nn.conf.layers.RBM)4 Layer (org.deeplearning4j.nn.api.Layer)2 OutputLayer (org.deeplearning4j.nn.conf.layers.OutputLayer)2 MultiLayerNetwork (org.deeplearning4j.nn.multilayer.MultiLayerNetwork)2 Test (org.junit.Test)2 StatsStorage (org.deeplearning4j.api.storage.StatsStorage)1 IrisDataSetIterator (org.deeplearning4j.datasets.iterator.impl.IrisDataSetIterator)1 MultiLayerConfiguration (org.deeplearning4j.nn.conf.MultiLayerConfiguration)1 NormalDistribution (org.deeplearning4j.nn.conf.distribution.NormalDistribution)1 DenseLayer (org.deeplearning4j.nn.conf.layers.DenseLayer)1 ComputationGraph (org.deeplearning4j.nn.graph.ComputationGraph)1 ScoreIterationListener (org.deeplearning4j.optimize.listeners.ScoreIterationListener)1 UIServer (org.deeplearning4j.ui.api.UIServer)1 StatsListener (org.deeplearning4j.ui.stats.StatsListener)1 InMemoryStatsStorage (org.deeplearning4j.ui.storage.InMemoryStatsStorage)1 Ignore (org.junit.Ignore)1 INDArray (org.nd4j.linalg.api.ndarray.INDArray)1 DataSetIterator (org.nd4j.linalg.dataset.api.iterator.DataSetIterator)1 Task (org.nd4j.linalg.heartbeat.reports.Task)1