Help I have error in my code
public class Main {
private static final Logger log = LoggerFactory.getLogger(Main.class);
private static final int batchSize = 15;
public static void main(String[] args) throws Exception {
long startTime = System.currentTimeMillis();
File file = new File("C:\\Users\\whail\\IdeaProjects\\DLRecognizer\\deeplearning\\src\\main\\resources");
File modelDir = new File(file.getPath() + "/model");
// create directory
if (!modelDir.exists()) { //noinspection ResultOfMethodCallIgnored
modelDir.mkdirs();
}
//create model
ComputationGraph model = createModel();
//construct the iterator
MultiDataSetIterator trainMulIterator = new MultiRecordDataSetIterator(batchSize, "6");
MultiDataSetIterator testMulIterator = new MultiRecordDataSetIterator(batchSize, "test");
//fit
model.setListeners(new ScoreIterationListener(10), new EvaluativeListener(testMulIterator, 1, InvocationType.EPOCH_END));
log.info("Эпоха запущена");
model.fit(trainMulIterator, 4);
//save
model.save(new File(modelDir.getPath() + "/model.zip"), true);
long endTime = System.currentTimeMillis();
System.out.println("=============run time===================== " + (endTime - startTime));
System.out.println("=====eval model=====test==================");
modelPredict(model, testMulIterator);
}
private static ComputationGraph createModel() {
ComputationGraphConfiguration config = new NeuralNetConfiguration.Builder()
.seed(123)
.gradientNormalization(GradientNormalization.RenormalizeL2PerLayer)
.l2(1e-3)
.updater(new Adam(1e-3))
.weightInit( WeightInit.XAVIER_UNIFORM)
.graphBuilder()
.addInputs("trainFeatures")
.setInputTypes(InputType.convolutional(50, 130, 3))
.setOutputs("out1", "out2", "out3", "out4", "out5", "out6")
.addLayer("cnn1", new ConvolutionLayer.Builder(new int[]{5, 5}, new int[]{1, 1}, new int[]{0, 0})
.nIn(1).nOut(48).activation( Activation.RELU).build(), "trainFeatures")
.addLayer("maxpool1", new SubsamplingLayer.Builder(PoolingType.MAX, new int[]{2,2}, new int[]{2, 2}, new int[]{0, 0})
.build(), "cnn1")
.addLayer("cnn2", new ConvolutionLayer.Builder(new int[]{5, 5}, new int[]{1, 1}, new int[]{0, 0})
.nOut(64).activation( Activation.RELU).build(), "maxpool1")
.addLayer("maxpool2", new SubsamplingLayer.Builder(PoolingType.MAX, new int[]{2,1}, new int[]{2, 1}, new int[]{0, 0})
.build(), "cnn2")
.addLayer("cnn3", new ConvolutionLayer.Builder(new int[]{3, 3}, new int[]{1, 1}, new int[]{0, 0})
.nOut(128).activation( Activation.RELU).build(), "maxpool2")
.addLayer("maxpool3", new SubsamplingLayer.Builder(PoolingType.MAX, new int[]{2,2}, new int[]{2, 2}, new int[]{0, 0})
.build(), "cnn3")
.addLayer("cnn4", new ConvolutionLayer.Builder(new int[]{4, 4}, new int[]{1, 1}, new int[]{0, 0})
.nOut(256).activation( Activation.RELU).build(), "maxpool3")
.addLayer("maxpool4", new SubsamplingLayer.Builder(PoolingType.MAX, new int[]{2,2}, new int[]{2, 2}, new int[]{0, 0})
.build(), "cnn4")
.addLayer("ffn0", new DenseLayer.Builder().nOut(3072)
.build(), "maxpool4")
.addLayer("ffn1", new DenseLayer.Builder().nOut(3072)
.build(), "ffn0")
.addLayer("out1", new OutputLayer.Builder(LossFunctions.LossFunction.NEGATIVELOGLIKELIHOOD)
.nOut(10).activation(Activation.SOFTMAX).build(), "ffn1")
.addLayer("out2", new OutputLayer.Builder(LossFunctions.LossFunction.NEGATIVELOGLIKELIHOOD)
.nOut(10).activation(Activation.SOFTMAX).build(), "ffn1")
.addLayer("out3", new OutputLayer.Builder(LossFunctions.LossFunction.NEGATIVELOGLIKELIHOOD)
.nOut(10).activation(Activation.SOFTMAX).build(), "ffn1")
.addLayer("out4", new OutputLayer.Builder(LossFunctions.LossFunction.NEGATIVELOGLIKELIHOOD)
.nOut(10).activation(Activation.SOFTMAX).build(), "ffn1")
.addLayer("out5", new OutputLayer.Builder(LossFunctions.LossFunction.NEGATIVELOGLIKELIHOOD)
.nOut(10).activation(Activation.SOFTMAX).build(), "ffn1")
.addLayer("out6", new OutputLayer.Builder(LossFunctions.LossFunction.NEGATIVELOGLIKELIHOOD)
.nOut(10).activation(Activation.SOFTMAX).build(), "ffn1")
.build();
// Construct and initialize model
ComputationGraph model = new ComputationGraph(config);
model.init();
return model;
}
private static void modelPredict(ComputationGraph model, MultiDataSetIterator iterator) {
int sumCount = 0;
int correctCount = 0;
while (iterator.hasNext()) {
MultiDataSet mds = iterator.next();
INDArray[] output = model.output(mds.getFeatures());
INDArray[] labels = mds.getLabels();
int dataNum = Math.min(batchSize, output[0].rows());
for (int dataIndex = 0; dataIndex < dataNum; dataIndex ++) {
StringBuilder reLabel = new StringBuilder();
StringBuilder peLabel = new StringBuilder();
INDArray preOutput;
INDArray realLabel;
for (int digit = 0; digit < 6; digit ++) {
preOutput = output[digit].getRow(dataIndex);
peLabel.append(Nd4j.argMax(preOutput).getInt(0));
realLabel = labels[digit].getRow(dataIndex);
reLabel.append(Nd4j.argMax(realLabel).getInt(0));
}
boolean equals = peLabel.toString().equals(reLabel.toString());
if (equals) {
correctCount ++;
}
sumCount ++;
log.info("real image {} prediction {} status {}", reLabel.toString(), peLabel.toString(), equals);
}
}
iterator.reset();
System.out.println("validate result : sum count =" + sumCount + " correct count=" + correctCount );
}
}
Error:
Exception in thread “main” org.deeplearning4j.exception.DL4JInvalidConfigException: DenseLayer (index=9, name=ffn0) nIn=0, nOut=3072; nIn and nOut must be > 0
at org.deeplearning4j.nn.conf.layers.LayerValidation.assertNInNOutSet(LayerValidation.java:55)
at org.deeplearning4j.nn.conf.layers.DenseLayer.instantiate(DenseLayer.java:58)
at org.deeplearning4j.nn.conf.graph.LayerVertex.instantiate(LayerVertex.java:106)
at org.deeplearning4j.nn.graph.ComputationGraph.init(ComputationGraph.java:581)
at org.deeplearning4j.nn.graph.ComputationGraph.init(ComputationGraph.java:442)
at org.mishaneyt.dlrecognizer.Main.createModel(Main.java:125)
at org.mishaneyt.dlrecognizer.Main.main(Main.java:55)