Search code examples
scaladeeplearning4jdl4j

dl4j MultiLayerNetwork does not have a constructor that take NeuralNetConfiguration (version 0.9.1)


I'm trying to write a simple Classifier example in Scala and looking at the dl4j examples a NeuralNetConfiguration instance is created (using a builder) and then passed as an argument to a MultiLayerNetwork class constructor. However, looking at the source code, MultiLayerNetwork does not have any constructor taking a NeuralNetConfiguration as an example. It looks like these examples are not up to date. Does anyone know how to do this in the last dl4j version?

I've manage to find a work around but I'm not sure this is the right way to do it:

val conf = new NeuralNetConfiguration.Builder()
   .seed(seed) 
   .iterations(iterations) 
   .learningRate(1e-6f) 
   .optimizationAlgo(OptimizationAlgorithm.CONJUGATE_GRADIENT) 
   .l1(1e-1).regularization(true).l2(2e-4)
   .useDropConnect(true)
   .layer(hiddenLayer)
   .layer(outputLayer)
   .build()
val confs: util.List[NeuralNetConfiguration] = new util.LinkedList();
confs.add(conf)
val builder = new MultiLayerConfiguration.Builder()
builder.setConfs(confs)
val model: MultiLayerNetwork = new MultiLayerNetwork(builder.build())

Solution

  • You need to follow the examples closer. The NeuralNetConfiguration() is your base parameters, then you list your layers (Look closer at any of the examples) and you finish the builder like that. That will give you a MultiLayerConfiguration.