首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何为本地镜像配置DL4j

如何为本地镜像配置DL4j
EN

Stack Overflow用户
提问于 2020-04-05 21:26:11
回答 1查看 113关注 0票数 0

我正在尝试使用DeepLearning4j对32x32图像进行从0到9的分类。我查找了许多示例和教程,但在将数据集拟合到网络时总是遇到一些异常。

我目前正在尝试使用带有ParentPathLabelGenerator和RecordReaderDataSetIterator的ImageRecordReader。

图像看起来加载得很好,但我在试穿的时候总是会碰到DL4JInvalidInputException。

代码语言:javascript
复制
        File parentDir = new File(dataPath);
        FileSplit filesInDir = new FileSplit(parentDir, NativeImageLoader.ALLOWED_FORMATS);
        ParentPathLabelGenerator labelMaker = new ParentPathLabelGenerator();

        BalancedPathFilter pathFilter = new BalancedPathFilter(new Random(), labelMaker, 100);
        InputSplit[] filesInDirSplit = filesInDir.sample(pathFilter, 80, 20);
        InputSplit trainData = filesInDirSplit[0];
        InputSplit testData = filesInDirSplit[1];

        ImageRecordReader recordReader = new ImageRecordReader(numRows, numColumns, 3, labelMaker);
        recordReader.initialize(trainData);

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

使用DenseLayer时:

代码语言:javascript
复制
Exception in thread "main" org.deeplearning4j.exception.DL4JInvalidInputException: Input that is not a matrix; expected matrix (rank 2), got rank 4 array with shape [1, 3, 32, 32]. Missing preprocessor or wrong input type? (layer name: layer0, layer index: 0, layer type: DenseLayer)

使用ConvolutionLayer时,错误发生在OutputLayer上:

代码语言:javascript
复制
Exception in thread "main" org.deeplearning4j.exception.DL4JInvalidInputException: Input that is not a matrix; expected matrix (rank 2), got rank 4 array with shape [1, 1000, 28, 28]. Missing preprocessor or wrong input type? (layer name: layer1, layer index: 1, layer type: OutputLayer)

是我加载图像的尝试不正确还是我的网络配置错误?

配置:

代码语言:javascript
复制
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
                .list()
                .layer(0, new ConvolutionLayer.Builder()
                        .nIn(3) // Number of input datapoints.
                        .nOut(1000) // Number of output datapoints.
                        .activation(Activation.RELU) // Activation function.
                        .weightInit(WeightInit.XAVIER) // Weight initialization.
                        .build())
                .layer(1, new OutputLayer.Builder(LossFunctions.LossFunction.NEGATIVELOGLIKELIHOOD)
                        .nIn(1000)
                        .nOut(outputNum)
                        .activation(Activation.SOFTMAX)
                        .weightInit(WeightInit.XAVIER)
                        .build())
                .build();
EN

回答 1

Stack Overflow用户

发布于 2020-04-06 01:39:20

最简单的方法是在定义网络时使用.setInputType配置选项。它将为您设置所有必要的预处理器,并计算所有正确的.nIn值。

再看一下这个示例https://github.com/eclipse/deeplearning4j-examples/blob/master/dl4j-examples/src/main/java/org/deeplearning4j/examples/convolution/mnist/MnistClassifier.java#L156

当您使用.setInputType方式设置网络时,您根本不需要设置任何.nIn值-您仍然可以这样做,这在我链接的示例中很明显,但通常没有很好的理由这样做。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61043337

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档