Skip to content

Instantly share code, notes, and snippets.

@StefanoSamele
StefanoSamele / gist:8506972f91a726b72fb6892649ee475c
Last active September 26, 2017 13:11
Casting a MultilayerNeuralNetwork imported from Vgg16 as Computationgraph
object Main extends App {
val zooModel: VGG16 = new VGG16()
val net: Model = zooModel.initPretrained(PretrainedType.IMAGENET)
val netAsCompGraph = net.asInstanceOf[ComputationGraph]
println(netAsCompGraph.summary())
}
@StefanoSamele
StefanoSamele / gist:5cc29af2ce0a7ad76379f2b170eee09c
Created September 15, 2017 09:07
Outputs of Atrous Convolution test
The output with cuDNN gpu backend is (for one channel, but the others are equal):
[[[[55.00, 82.00, 109.00, 136.00, 163.00, 190.00, 217.00, 244.00, 271.00, 298.00, 325.00, 352.00],
[82.00, 109.00, 136.00, 163.00, 190.00, 217.00, 244.00, 271.00, 298.00, 325.00, 352.00, 379.00],
[109.00, 136.00, 163.00, 190.00, 217.00, 244.00, 271.00, 298.00, 325.00, 352.00, 379.00, 406.00],
[136.00, 163.00, 190.00, 217.00, 244.00, 271.00, 298.00, 325.00, 352.00, 379.00, 406.00, 433.00],
[163.00, 190.00, 217.00, 244.00, 271.00, 298.00, 325.00, 352.00, 379.00, 406.00, 433.00, 460.00],
[190.00, 217.00, 244.00, 271.00, 298.00, 325.00, 352.00, 379.00, 406.00, 433.00, 460.00, 487.00],
[217.00, 244.00, 271.00, 298.00, 325.00, 352.00, 379.00, 406.00, 433.00, 460.00, 487.00, 514.00],
[244.00, 271.00, 298.00, 325.00, 352.00, 379.00, 406.00, 433.00, 460.00, 487.00, 514.00, 541.00],
[271.00, 298.00, 325.00, 35
@StefanoSamele
StefanoSamele / gist:90c3deda6e07c9452c5514d7854f2b50
Created September 15, 2017 09:02
Test network for Atrous Convolution
object cuDNNAtrousTest extends App {
val height = 24
val width = 24
val depth = 3
var img = Nd4j.ones(1, depth, height, width)
for (i <- 0 until depth) {
for (j <- 0 until height) {
@StefanoSamele
StefanoSamele / gist:93a3d602d3c55585cf79d8f4c807da75
Created September 14, 2017 14:57
Max Pooling Test CPU vs GPU
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)
@StefanoSamele
StefanoSamele / gist:23b829a170f4400ce761873d2da2abcf
Created September 14, 2017 10:03
IUpdater applySchedules method issue
Exception in thread "main" java.lang.NoSuchMethodError: org.nd4j.linalg.learning.config.IUpdater.applySchedules(ID)V
at org.deeplearning4j.nn.conf.layers.LayerValidation.updaterValidation(LayerValidation.java:85)
at org.deeplearning4j.nn.conf.layers.LayerValidation.updaterValidation(LayerValidation.java:35)
at org.deeplearning4j.nn.conf.NeuralNetConfiguration$Builder.copyConfigToLayer(NeuralNetConfiguration.java:1378)
at org.deeplearning4j.nn.conf.NeuralNetConfiguration$Builder.configureLayer(NeuralNetConfiguration.java:1318)
at org.deeplearning4j.nn.conf.NeuralNetConfiguration$Builder.build(NeuralNetConfiguration.java:1301)
at org.deeplearning4j.nn.conf.ComputationGraphConfiguration$GraphBuilder.addLayer(ComputationGraphConfiguration.java:652)
at org.deeplearning4j.nn.conf.ComputationGraphConfiguration$GraphBuilder.addLayer(ComputationGraphConfiguration.java:636)
at org.deeplearning4j.nn.modelimport.keras.KerasModel.getComputationGraphConfiguration(KerasModel.java:322)
at org.deeplearning4j.nn.model
@StefanoSamele
StefanoSamele / getActivation.txt
Last active September 5, 2017 16:21
Adjustment for ActivationSoftmax getActivation method, to handle 3D input.
public INDArray getActivation(INDArray in, boolean training) {
switch (in.rank()){
case 2:
Nd4j.getExecutioner().execAndReturn(new SoftMax(in));
return in;
case 3:
//TODO We should consider the problem of selecting a different dimension as candidate for the softmax op
INDArray partial_result = Nd4j.zeros(in.shape()[0], in.shape()[2]);
for (int ind = 0; ind < in.shape()[1]; ind++ ) {
@StefanoSamele
StefanoSamele / TestSoftmaxActivation
Created September 5, 2017 13:08
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)
x = np.array([[[2, 3, 1, 0, 10], [4, 5, 6, 7, 11], [8, 9, 10, 11, 12]], [[2, 3, 1, 0, 13], [4, 5, 6, 7, 14], [8, 9, 10, 12, 15]], [[2, 3, 1, 0, 16], [4, 5, 6, 7, 17], [8, 9, 10, 13, 18]]])
threshold = 0.5
w = np.random.rand(3, 3, 5)
mask2 = w > threshold
print(x)
print(mask2)
x = x[mask2]
print(x)
@StefanoSamele
StefanoSamele / modelssd300.json
Created August 19, 2017 19:12
.json file of an SSD net taken from https://github.com/rykov8/ssd_keras
{
"class_name": "Model",
"config": {
"input_layers": [
[
"input_1",
0,
0
]
],
HDF5-DIAG: Error detected in HDF5 (1.10.0-patch1) thread 0:
#000: H5G.c line 474 in H5Gopen2(): unable to open group
major: Symbol table
minor: Can't open object
#001: H5Gint.c line 289 in H5G__open_name(): group not found
major: Symbol table
minor: Object not found
#002: H5Gloc.c line 430 in H5G_loc_find(): can't find object
major: Symbol table
minor: Object not found