Created
September 14, 2017 14:57
-
-
Save StefanoSamele/93a3d602d3c55585cf79d8f4c807da75 to your computer and use it in GitHub Desktop.
Max Pooling Test CPU vs GPU
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val height = 8 | |
val width = 8 | |
val depth = 3 | |
var img = Nd4j.ones(1, depth, height, width) | |
for (i <- 0 until depth) { | |
for (j <- 0 until height) { | |
for (k <- 0 until width) { | |
img.put(Array(NDArrayIndex.point(0), NDArrayIndex.point(i), NDArrayIndex.point(j), NDArrayIndex.point(k)), j+k) | |
} | |
} | |
} | |
val builder_pooling = new SubsamplingLayer.Builder(SubsamplingLayer.PoolingType.MAX) | |
.name("max_pooling") | |
.kernelSize(2, 2) | |
.stride(1, 1) | |
.build | |
private def convInit(name: String, in: Int, out: Int, kernel: Array[Int], stride: Array[Int], pad: Array[Int], bias: Double): ConvolutionLayer = | |
return new ConvolutionLayer.Builder(kernel, stride, pad).name(name).nIn(in).nOut(out).biasInit(bias).activation(Activation.RELU).build | |
val conf: MultiLayerConfiguration = new NeuralNetConfiguration.Builder() | |
.iterations(1) | |
.weightInit(WeightInit.ONES) | |
.list | |
.layer(0, convInit("cnn1", depth, 1, Array[Int](3, 3), Array[Int](1, 1), Array[Int](0, 0), 0)) | |
.layer(1, builder_pooling) | |
.setInputType(InputType.convolutional(height, width, depth)).build | |
val net = new MultiLayerNetwork(conf) | |
net.init() | |
val output = net.output(img) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment