CNN Multi feature Exception

Hi,
I am getting below exception :
Invalid input, does not match configuration: expected [minibatch, numChannels=10, inputHeight=8, inputWidth=8] but got input array of shape [43, 10, 8, 3]

  • at org.deeplearning4j.nn.conf.preprocessor.CnnToFeedForwardPreProcessor.preProcess(CnnToFeedForwardPreProcessor.java:112)*

@anonhm09 post your configuration please. Ideally it’s something we can run standalone ourselves. That would include a sample input as well.

@agibsonccc

dataset can be download from here.

DataSet dataSet = new DataSet() ;
dataSet.load(new File());

Features Rank: 4, DataType: DOUBLE, Offset: 0, Order: c, Shape: [43,1,7,2], Stride: [14,14,2,1]
Labels Rank: 3, DataType: DOUBLE, Offset: 0, Order: c, Shape: [43,1,1], Stride: [1,1,1]

Here Model conf:

MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
			.trainingWorkspaceMode(WorkspaceMode.ENABLED).inferenceWorkspaceMode(WorkspaceMode.ENABLED)
			.seed(RANDOM_SEED)
			.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
		    .updater(new RmsProp.Builder().learningRate(.001).rmsDecay(.001).build())
			.layer(0, new ConvolutionLayer.Builder(2,2).nIn(1).nOut(10).padding(1,1).stride(1,1).activation(Activation.TANH).build())
		    .layer(1, new SubsamplingLayer.Builder(PoolingType.MAX).kernelSize(1,1) .stride(1,1).build())
		 	.layer(2, new DenseLayer.Builder().nOut(40).activation(Activation.TANH).build())
		 	.layer(3, new OutputLayer.Builder(LossFunctions.LossFunction.MEAN_ABSOLUTE_ERROR).nOut(1).activation(Activation.TANH)
			.setInputType(InputType.convolutional(7, 7,1))
			.build();
			
	MultiLayerNetwork model = new MultiLayerNetwork(conf);
	model.setInputMiniBatchSize(10);
	model.init();

training sample input dataSet(github file) :
===========INPUT===================
[[[[ 12.2289, 1.0000],
[ 13.4411, 2.0000],
[ 10.6273, 3.0000],
[ 10.4183, 4.0000],
[ 10.9446, 5.0000],
[ 10.3468, 6.0000],
[ 7.5371, 7.0000]]]]
=================OUTPUT==================
[[[7.3623]]]

total 43 is same as above.

@anonhm09 sorry just had a chance to look at this.
For the future: please just give me an example I can run. Your code was incomplete (it didn’t even compile)
I was able to piece together what you wanted to do. The input data set is in the format NCHW:
Number of examples, Number of Channels, Height, Width

Your input dataset was a height of 7 and a width of 2.

This will work:

 ConvolutionLayer build = new ConvolutionLayer.Builder(2, 2).nOut(10).padding(1, 1).stride(1, 1)
                .activation(Activation.TANH).build();
        long RANDOM_SEED = 12345;
        MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
                .updater(new RmsProp.Builder().learningRate(.001).rmsDecay(.001).build())
                .list(build,
                        new SubsamplingLayer.Builder(PoolingType.MAX).kernelSize(1,1) .stride(1,1).build(),
                        new DenseLayer.Builder().nOut(40).activation(Activation.TANH).build(),
                        new OutputLayer.Builder(LossFunctions.LossFunction.MEAN_ABSOLUTE_ERROR).nOut(1).activation(Activation.TANH).build())

                .setInputType(InputType.convolutional(7, 2,1))
                .build();

        MultiLayerNetwork model = new MultiLayerNetwork(conf);
        model.init();

        DataSet dataSet = new DataSet();
        dataSet.load(new File("abc.bin"));
        INDArray features = dataSet.getFeatures();
        model.output(features);

Also, not sure what version you were using. Please try to stick to the examples if you don’t know the API very well. That has best practices. You can find those here: