nd4j中的简单卷积

时间:2017-10-16 21:46:48

标签: convolution nd4j

我无法在nd4j中使用简单的卷积,有关此特定主题的文档很简洁。我想做什么:

patterns

无论是值还是卷积类型,我总是得到相同的异常(见下文)。当nd4j试图将值数组转换为复数数组以执行我认为的傅里叶变换时,似乎会发生错误。

我尝试了几个版本的nd4j(0.9.1 - 0.8.0 - 0.7.0),但无济于事。有人可以帮忙吗?

INDArray values = Nd4j.create(new double[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10});
INDArray kernel = Nd4j.create(new double[]{0.5,0.5});

INDArray conv = Nd4j.getConvolution().convn(values, kernel, Convolution.Type.VALID);

1 个答案:

答案 0 :(得分:0)

这有点棘手,因为ND4j当前不支持数学卷积。您必须制定自己的实现。

    double[] rawData = {12,10,15,12,10,11,15,12,12};
    INDArray data = Nd4j.create(rawData);
    double[] rawFilter = {1.0 / 2, 0, 1.0 / 2};
    INDArray filter = Nd4j.create(rawFilter);        
    Nd4jConv1d convolution = new Nd4jConv1d(1, 1, (int) filter.shape()[1], 1, 0);
    INDArray output = convolution.forward(data, filter);

如在https://github.com/deeplearning4j/deeplearning4j/blob/af7155d61dc810d3e7139f15f98810e0255b2e17/arbiter/arbiter-deeplearning4j/src/test/java/org/deeplearning4j/arbiter/multilayernetwork/MNISTOptimizationTest.java

中所示

注意:您需要附加的类Nd4jConv1d。进入仓库获取它