Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Deep learning 使用MNIST deeplearning4j示例时出现代码错误_Deep Learning_Mnist_Deeplearning4j - Fatal编程技术网

Deep learning 使用MNIST deeplearning4j示例时出现代码错误

Deep learning 使用MNIST deeplearning4j示例时出现代码错误,deep-learning,mnist,deeplearning4j,Deep Learning,Mnist,Deeplearning4j,请帮帮我!我正在使用deeplearning4j进行一个项目。MNIST示例运行得很好,但我的数据集出现了一个错误。 我的数据集有两个输出 int height = 45; int width = 800; int channels = 1; int rngseed = 123; Random randNumGen = new Random(rngseed); int batchSize = 128; int outputNum = 2; int numEpochs = 15; File tra

请帮帮我!我正在使用
deeplearning4j
进行一个项目。MNIST示例运行得很好,但我的数据集出现了一个错误。 我的数据集有两个输出

int height = 45;
int width = 800;
int channels = 1;
int rngseed = 123;
Random randNumGen = new Random(rngseed);
int batchSize = 128;
int outputNum = 2;
int numEpochs = 15;
File trainData = new File("C:/Users/JHP/Desktop/learningData/training");
File testData = new File("C:/Users/JHP/Desktop/learningData/testing");
FileSplit train = new FileSplit(trainData, NativeImageLoader.ALLOWED_FORMATS, randNumGen);
FileSplit test = new FileSplit(testData, NativeImageLoader.ALLOWED_FORMATS, randNumGen);
ParentPathLabelGenerator labelMaker = new ParentPathLabelGenerator();

ImageRecordReader recordReader = new ImageRecordReader(height, width, channels, labelMaker);
ImageRecordReader recordReader2 = new ImageRecordReader(height, width, channels, labelMaker);
recordReader.initialize(train);
recordReader2.initialize(test);

DataSetIterator dataIter = new RecordReaderDataSetIterator(recordReader, batchSize, 1, outputNum);
DataSetIterator testIter = new RecordReaderDataSetIterator(recordReader2, batchSize, 1, outputNum);

DataNormalization scaler = new ImagePreProcessingScaler(0, 1);
scaler.fit(dataIter);
dataIter.setPreProcessor(scaler);

System.out.println("Build model....");
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
        .seed(rngseed)
        .optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
        .iterations(1)
        .learningRate(0.006)
        .updater(Updater.NESTEROVS).momentum(0.9)
        .regularization(true).l2(1e-4)
        .list()
        .layer(0,   new DenseLayer.Builder()
                .nIn(height * width)
                .nOut(1000)
                .activation(Activation.RELU)
                .weightInit(WeightInit.XAVIER)
                .build()
                )
        .layer(1, newOutputLayer.Builder(LossFunction.NEGATIVELOGLIKELIHOOD)
                .nIn(1000)
                .nOut(outputNum)
                .activation(Activation.SOFTMAX)
                .weightInit(WeightInit.XAVIER)
                .build()
                )
        .pretrain(false).backprop(true)
        .build();

MultiLayerNetwork model = new MultiLayerNetwork(conf);
model.init();
model.setListeners(new ScoreIterationListener(1));

System.out.println("Train model....");
for (int i = 0; i < numEpochs; i++) {
    try {
        model.fit(dataIter);
    } catch (Exception e) {
        System.out.println(e);
    }
}
int高度=45;
整数宽度=800;
int通道=1;
int rngseed=123;
Random randNumGen=新随机(rngseed);
int batchSize=128;
int outputNum=2;
int numEpochs=15;
文件trainData=新文件(“C:/Users/JHP/Desktop/learningData/training”);
文件testData=新文件(“C:/Users/JHP/Desktop/learningData/testing”);
FileSplit train=新的FileSplit(trainData,NativeImageLoader.ALLOWED_格式,randNumGen);
FileSplit test=新的FileSplit(testData,NativeImageLoader.ALLOWED_格式,randNumGen);
ParentPathLabelGenerator labelMaker=新的ParentPathLabelGenerator();
ImageRecordReader recordReader=新的ImageRecordReader(高度、宽度、通道、labelMaker);
ImageRecordReader recordReader2=新的ImageRecordReader(高度、宽度、通道、labelMaker);
recordReader.initialize(列车);
recordReader2.初始化(测试);
DataSetIterator dataIter=新的RecordReaderDataSetIterator(recordReader,batchSize,1,outputNum);
DataSetIterator testter=新的RecordReaderDataSetIterator(recordReader2,batchSize,1,outputNum);
DataNormalization scaler=新的ImagePreProcessingScaler(0,1);
scaler.fit(dataIter);
数据集预处理器(定标器);
System.out.println(“构建模型…”);
多层配置conf=new NeuralNetConfiguration.Builder()
.种子(RNG种子)
.优化算法(优化算法.随机梯度下降)
.迭代次数(1)
.学习率(0.006)
.updater(updater.NESTEROVS).momentum(0.9)
.正则化(真)。l2(1e-4)
.list()
.layer(0,新的DenseLayer.Builder()
.nIn(高度*宽度)
.nOut(1000)
.activation(activation.RELU)
.weightInit(weightInit.XAVIER)
.build()
)
.layer(1,newOutputLayer.Builder(LossFunction.NEGATIVELOGLIKELIHOOD)
.nIn(1000)
.nOut(outputNum)
.activation(activation.SOFTMAX)
.weightInit(weightInit.XAVIER)
.build()
)
.pretrain(假)。backprop(真)
.build();
多层网络模型=新的多层网络(conf);
model.init();
setListeners(新的ScoreIterationListener(1));
System.out.println(“列车模型…”);
对于(int i=0;i
错误是

org.deeplearning4j.exception.DL4JInvalidInputException:输入 不是矩阵;期望矩阵(秩2),得到具有形状的秩4数组 [128,1,45,800]


你把神经网络初始化错了。如果您仔细查看dl4j examples repo中的每个cnn示例(提示:这是您应该从中提取代码的规范源,其他任何内容都可能无效或过时:) 您会注意到,在我们的所有示例中,我们都有一个inputType配置:

您应该使用多种类型,但决不能手动设置nIn。没什么

对于mnist,我们使用卷积平面,并将其转换为4d数据集


Mnist从平面向量开始,但cnn只理解3d数据。我们将为您进行转换和重塑。

我认为有必要将DataSetIterator函数更改为另一个函数。在MNIST示例中,这类似于将数据导入函数。DataSeterator MNISTRAIN=新的MNIStDataSeterator(batchSize,true,rngseed);我不知道该使用什么函数。@TriV TriV非常感谢您让我知道需要改进什么!我不知道,因为我是第一次使用堆栈溢出。非常感谢你!