gpt4 book ai didi

java - 如何为本地镜像配置DL4j

转载 作者:行者123 更新时间:2023-12-01 17:35:52 27 4
gpt4 key购买 nike

我正在尝试使用DeepLearning4j将0x范围内的32x32图像分类为数字。
我查阅了许多示例和教程,但是在将数据集拟合到网络时总是遇到一些异常。

我目前正在尝试将ImageRecordReader与ParentPathLabelGenerator和RecordReaderDataSetIterator一起使用。

图像似乎可以很好地加载,但是安装时我总是遇到DL4JInvalidInputException。

        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时:

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上:

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)


我尝试加载图像的尝试是否不正确或我的网络配置不正确?

组态:

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();

最佳答案

最简单的方法是在定义网络时使用.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值-仍然可以,正如我所链接的示例中所示,但是通常没有任何好处。这样做的理由。

关于java - 如何为本地镜像配置DL4j,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61043337/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com