Skip to content

Instantly share code, notes, and snippets.

@StefanoSamele
Created September 5, 2017 13:08
Show Gist options
  • Save StefanoSamele/cb0400a9fcdaa84e0b45200febd6a33e to your computer and use it in GitHub Desktop.
Save StefanoSamele/cb0400a9fcdaa84e0b45200febd6a33e to your computer and use it in GitHub Desktop.
Simple computationgraph to test the softmax activation
object TestSoftmaxActivation extends App {
val height = 5
val width = 5
val depth = 3
//var img = Nd4j.ones(1, depth, height, width)
var array = Array(3.87, -0.31, -0.22, -0.42, -0.01, 5.79, -0.66, -0.20, -0.80, -0.03, 9.78, -0.23, -0.37, -0.51, -0.47, 5.76, -0.09, 0.40, -0.96, -0.78, -0.47, 4.05, -0.44, -0.37, -0.22, -0.14, -0.34, -0.62, 0.31, 9.78, 0.17, 0.50, -0.37, 0.02, -0.26, -0.61, 0.18, 0.03, 0.67, 9.78, -0.50, -0.62, 3.95, -0.71, -0.51, 0.07, -0.58, 9.78, -0.45, 0.12, 9.78, 0.31, 0.42, -0.27, 9.78, -0.42, -0.78, 0.56, -0.06, 9.78, -0.84, -0.41, -0.62, 4.03, -0.56, -0.29, -0.46, 0.06, 9.78, -0.27, 0.17, -1.04, -0.03, -0.48, -0.38)
println(array.length)
var img = Nd4j.create(Array(depth, height, width), array)
val activation: IActivation = new ActivationSoftmax
val activation_builder = new ActivationLayer.Builder()
.activation(activation)
.name("NormalizeLayer")
.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).build
val conf: ComputationGraphConfiguration = new NeuralNetConfiguration.Builder()
.graphBuilder()
.addInputs("input")
.addLayer("L1", convInit("cnn1", depth, 3, Array[Int](1, 1), Array[Int](1, 1), Array[Int](0, 0), 0), "input")
.addLayer("L2", activation_builder, "L1")
.setOutputs("L2", "L1")
.build
val net = new ComputationGraph(conf)
net.init()
val output = net.output(img)
println(output(0).eq(output(1)))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment