0

当我运行以下代码时:

model.output(samples).getDouble(0);

我收到错误:

org.deeplearning4j.exception.DL4JInvalidInputException: 
Cannot do forward pass in Convolution layer (layer name = conv1d_1, layer index = 0): input array channels does not match CNN layer configuration 
(data input channels = 80, [minibatch,inputDepth,height,width]=[1, 80, 3, 1]; expected input channels = 3) 
(layer name: conv1d_1, layer index: 0, layer type: Convolution1DLayer)

我将数据创建为float[]数组,长度 = 240。INDArray 的创建:

 INDArray features = Nd4j.create(data, new int[]{1, 240}, 'c');

这是我的 keras 模型:

model = Sequential()
model.add(Reshape((const.PERIOD, const.N_FEATURES), input_shape=(240,)))
model.add(Conv1D(100, 10, activation='relu', input_shape=(const.PERIOD, const.N_FEATURES)))
model.add(Conv1D(100, 10, activation='relu'))
model.add(MaxPooling1D(const.N_FEATURES))
model.add(Conv1D(160, 10, activation='relu'))
model.add(Conv1D(160, 10, activation='relu'))
model.add(Flatten())
model.add(Dropout(0.5))
model.add(Dense(7, activation='softmax'))
model.summary()
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])

其中 PERIOD = 80,N_FEATURES = 3

如果我将形状设置为:

 INDArray features = Nd4j.create(data, new int[]{240, 1});

那么错误是:

IllegalStateException: Input shape [240, 1] and output shape[240, 1] do not match
    at org.deeplearning4j.nn.modelimport.keras.preprocessors.ReshapePreprocessor.preProcess(ReshapePreprocessor.java:103)
    at org.deeplearning4j.nn.multilayer.MultiLayerNetwork.outputOfLayerDetached(MultiLayerNetwork.java:1256)
    at org.deeplearning4j.nn.multilayer.MultiLayerNetwork.output(MultiLayerNetwork.java:2340)
    at org.deeplearning4j.nn.multilayer.MultiLayerNetwork.output(MultiLayerNetwork.java:2303)
    at org.deeplearning4j.nn.multilayer.MultiLayerNetwork.output(MultiLayerNetwork.java:2294)
    at org.deeplearning4j.nn.multilayer.MultiLayerNetwork.output(MultiLayerNetwork.java:2281)
    at org.deeplearning4j.nn.multilayer.MultiLayerNetwork.output(MultiLayerNetwork.java:2377)
4

1 回答 1

0

你能提出问题吗?这看起来像一个错误。谢谢。 https://github.com/eclipse/deeplearning4j/issues

于 2019-11-16T00:13:51.017 回答