java - DeepLearning4J IllegalArgumentException for CNN with custom Matrix -
i have custom 7(height) , 24(width) matrix input used training. output labels age ( young, mature, old). go deeplearning4j convolutional neural networks.
after building basic convolutional neural network first training item gives following error , have no clue about.
exception in thread "main" java.lang.illegalargumentexception: invalid size index 2 wher it's >= rank 2 @ org.nd4j.linalg.api.ndarray.basendarray.size(basendarray.java:4066) @ org.deeplearning4j.nn.layers.convolution.convolutionlayer.preoutput(convolutionlayer.java:192) @ org.deeplearning4j.nn.layers.convolution.convolutionlayer.activate(convolutionlayer.java:247) @ org.deeplearning4j.nn.graph.vertex.impl.layervertex.doforward(layervertex.java:88) @ org.deeplearning4j.nn.graph.computationgraph.feedforward(computationgraph.java:983) @ org.deeplearning4j.nn.graph.computationgraph.computegradientandscore(computationgraph.java:889)
my dl4j code
//model config here multilayerconfiguration.builder builder = new neuralnetconfiguration.builder() .seed(seed) .iterations(iterations) .regularization(true).l2(0.0005) .learningrate(0.01)//.biaslearningrate(0.02) //.learningratedecaypolicy(learningratepolicy.inverse).lrpolicydecayrate(0.001).lrpolicypower(0.75) .weightinit(weightinit.xavier) .optimizationalgo(optimizationalgorithm.stochastic_gradient_descent) .updater(updater.nesterovs).momentum(0.9) .list() .layer(0, new convolutionlayer.builder(4, 1) //nin , nout specify depth. nin here nchannels , nout number of filters applied .name("hzvt1") .nin(nchannels) .stride(1, 1) .nout(26) .activation("relu")//.activation("identity") .build()) .layer(1, new outputlayer.builder(lossfunctions.lossfunction.negativeloglikelihood) .nout(outputnum) .activation("softmax") .build()) .setinputtype(inputtype.convolutional(nchannels,height,width)) .backprop(true).pretrain(false); //model build here model.fit(wmtrain);multilayerconfiguration conf = builder.build(); model.fit(wmtrain);multilayernetwork model = new multilayernetwork(conf); model.init(); //training data creation here indarray weekmatrix = nd4j.ones(dlagegender.nchannels,dlagegender.height*dlagegender.width); double[] vector = new double[] { 0.0, 1.0, 0.0 }; indarray intlabels = nd4j.create(vector); dataset ds=new dataset(weekmatrix,intlabels); //train first item model.fit(wmtrain);
i using dl4j version 0.6 , java version 1.8, maven 3.3+
i suspect bug in library.
with of gitter support. found out model , input not matching. correct working code follows.
i hope dl4j error/exception messages more clear in next releases.
log.info("build model...."); system.out.println("building model..."); multilayerconfiguration.builder builder = new neuralnetconfiguration.builder() .seed(seed) .iterations(iterations) .regularization(true).l2(0.0005) .learningrate(0.01)//.biaslearningrate(0.02) //.learningratedecaypolicy(learningratepolicy.inverse).lrpolicydecayrate(0.001).lrpolicypower(0.75) .weightinit(weightinit.xavier) .optimizationalgo(optimizationalgorithm.stochastic_gradient_descent) .updater(updater.nesterovs).momentum(0.9) .list() .layer(0, new convolutionlayer.builder(4, 1) //nin , nout specify depth. nin here nchannels , nout number of filters applied .name("hzvt1") .nin(nchannels) .stride(1, 1) .nout(26) .activation("relu")//.activation("identity") .build()) .layer(1, new outputlayer.builder(lossfunctions.lossfunction.negativeloglikelihood) .nout(classes) .activation("softmax") .build()) .setinputtype(inputtype.convolutional(height,width,nchannels)) .backprop(true).pretrain(false); //model build here model.fit(wmtrain);multilayerconfiguration conf = builder.build(); model.fit(wmtrain);multilayernetwork model = new multilayernetwork(conf); model.init(); //training data creation here indarray weekmatrix = nd4j.ones(new int[]{1,dlagegender.nchannels,dlagegender.height,dlagegender.width}); indarray intlabels; double[] vector = new double[] { 0.0, 1.0, }; intlabels = nd4j.create(vector); dataset ds=new dataset(weekmatrix,intlabels); log.info("train model...."); model.setlisteners(new scoreiterationlistener(1)); model.fit(wmtrain); system.out.println("data train ok.");
Comments
Post a Comment