Skip to content

Commit 10c1b5c

Browse files
MarcelWiedenmanndietzc
authored andcommitted
Initial commit
0 parents  commit 10c1b5c

File tree

228 files changed

+24651
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

228 files changed

+24651
-0
lines changed

.gitattributes

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
* text=auto !eol
2+
**/.api_filters text diff=xml
3+
**/.classpath text diff=xml
4+
**/.project text diff=xml
5+
**/MANIFEST.MF text
6+
**/build.properties text
7+
**/p2.inf text
8+
*.ai binary filter=lfs diff=lfs merge=lfs
9+
*.bmp binary
10+
*.cspex text diff=xml
11+
*.gif binary
12+
*.html text diff=html
13+
*.ico binary
14+
*.jar binary filter=lfs diff=lfs merge=lfs
15+
*.java text diff=java
16+
*.jpg binary
17+
*.js text
18+
*.json text
19+
*.jsx text
20+
*.png binary
21+
*.prefs text
22+
*.sh text
23+
*.svg text diff=xml
24+
*.xml text diff=xml
25+
*.xsd text diff=xml
26+
*.css text diff=css
27+
*.zip binary filter=lfs diff=lfs merge=lfs
28+
*.pdf binary filter=lfs diff=lfs merge=lfs
29+
*.dll binary filter=lfs diff=lfs merge=lfs
30+
*.so binary filter=lfs diff=lfs merge=lfs
31+
*.dylib binary filter=lfs diff=lfs merge=lfs
32+
*.jsa binary filter=lfs diff=lfs merge=lfs
33+
*.sym binary filter=lfs diff=lfs merge=lfs
34+
*.msi binary filter=lfs diff=lfs merge=lfs
35+
*.tar.gz binary filter=lfs diff=lfs merge=lfs

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*/bin/
2+
*/target/
3+
*/build/
4+
*/.settings/
5+
6+
*.pyc*

.lfsconfig

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[lfs]
2+
url = https://bitbucket.org/KNIME/knime-deeplearning.git/info/lfs

LICENSE

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This repository contains parts of the KNIME Analytics Platform as a bundle of various modules. Each module is released under its own license. Please refer to the [project/directory/package] of the module to find it's corresponding license. The KNIME trademark and logo and OPEN FOR INNOVATION are registered in the United States and/or Germany, owned by KNIME GmbH. All other trademarks belong to their respective owners.

org.knime.dl.keras.testing/.classpath

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
4+
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
5+
<classpathentry kind="src" path="src"/>
6+
<classpathentry kind="output" path="bin"/>
7+
</classpath>

org.knime.dl.keras.testing/.project

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>org.knime.dl.keras.testing</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.pde.ManifestBuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
<buildCommand>
19+
<name>org.eclipse.pde.SchemaBuilder</name>
20+
<arguments>
21+
</arguments>
22+
</buildCommand>
23+
</buildSpec>
24+
<natures>
25+
<nature>org.eclipse.pde.PluginNature</nature>
26+
<nature>org.eclipse.jdt.core.javanature</nature>
27+
</natures>
28+
</projectDescription>

org.knime.dl.keras.testing/LICENSE.txt

+711
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Manifest-Version: 1.0
2+
Bundle-ManifestVersion: 2
3+
Bundle-Name: KNIME Deep Learning - Keras Integration Testing
4+
Bundle-SymbolicName: org.knime.dl.keras.testing;singleton:=true
5+
Bundle-Version: 3.4.0.qualifier
6+
Bundle-ClassPath: .
7+
Bundle-Vendor: KNIME GmbH, Konstanz, Germany
8+
Fragment-Host: org.knime.dl.keras;bundle-version="3.4.0.qualifier"
9+
Require-Bundle: org.junit;bundle-version="4.12.0",
10+
org.knime.testing;bundle-version="3.4.0"
11+
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
bin.includes = fragment.xml,\
2+
META-INF/,\
3+
data/,\
4+
external-licenses/
5+
jars.compile.order = knime-dl-core.jar
6+
source.. = src/
7+
output.. = bin/
8+
src.includes = src/,\
9+
data/,\
10+
external-licenses/
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"config": [{"config": {"activation": "tanh", "bias_regularizer": null, "kernel_initializer": {"config": {"seed": null, "maxval": 0.05, "minval": -0.05}, "class_name": "RandomUniform"}, "use_bias": true, "trainable": true, "kernel_regularizer": null, "dtype": "float32", "activity_regularizer": null, "bias_constraint": null, "units": 100, "kernel_constraint": null, "batch_input_shape": [null, 2], "name": "dense_1", "bias_initializer": {"config": {}, "class_name": "Zeros"}}, "class_name": "Dense"}, {"config": {"name": "dropout_1", "rate": 0.2, "trainable": true}, "class_name": "Dropout"}, {"config": {"activation": "tanh", "bias_regularizer": null, "kernel_initializer": {"config": {"seed": null, "maxval": 0.05, "minval": -0.05}, "class_name": "RandomUniform"}, "use_bias": true, "trainable": true, "kernel_regularizer": null, "activity_regularizer": null, "units": 100, "kernel_constraint": null, "name": "dense_2", "bias_constraint": null, "bias_initializer": {"config": {}, "class_name": "Zeros"}}, "class_name": "Dense"}, {"config": {"name": "dropout_2", "rate": 0.2, "trainable": true}, "class_name": "Dropout"}, {"config": {"activation": "softmax", "bias_regularizer": null, "kernel_initializer": {"config": {"seed": null, "maxval": 0.05, "minval": -0.05}, "class_name": "RandomUniform"}, "use_bias": true, "trainable": true, "kernel_regularizer": null, "activity_regularizer": null, "units": 2, "kernel_constraint": null, "name": "dense_3", "bias_constraint": null, "bias_initializer": {"config": {}, "class_name": "Zeros"}}, "class_name": "Dense"}], "keras_version": "2.0.4", "class_name": "Sequential", "backend": "tensorflow"}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
backend: tensorflow
2+
class_name: Sequential
3+
config:
4+
- class_name: Dense
5+
config:
6+
activation: tanh
7+
activity_regularizer: null
8+
batch_input_shape: !!python/tuple [null, 2]
9+
bias_constraint: null
10+
bias_initializer:
11+
class_name: Zeros
12+
config: {}
13+
bias_regularizer: null
14+
dtype: float32
15+
kernel_constraint: null
16+
kernel_initializer:
17+
class_name: RandomUniform
18+
config: {maxval: 0.05, minval: -0.05, seed: null}
19+
kernel_regularizer: null
20+
name: dense_1
21+
trainable: true
22+
units: 100
23+
use_bias: true
24+
- class_name: Dropout
25+
config: {name: dropout_1, rate: 0.2, trainable: true}
26+
- class_name: Dense
27+
config:
28+
activation: tanh
29+
activity_regularizer: null
30+
bias_constraint: null
31+
bias_initializer:
32+
class_name: Zeros
33+
config: {}
34+
bias_regularizer: null
35+
kernel_constraint: null
36+
kernel_initializer:
37+
class_name: RandomUniform
38+
config: {maxval: 0.05, minval: -0.05, seed: null}
39+
kernel_regularizer: null
40+
name: dense_2
41+
trainable: true
42+
units: 100
43+
use_bias: true
44+
- class_name: Dropout
45+
config: {name: dropout_2, rate: 0.2, trainable: true}
46+
- class_name: Dense
47+
config:
48+
activation: softmax
49+
activity_regularizer: null
50+
bias_constraint: null
51+
bias_initializer:
52+
class_name: Zeros
53+
config: {}
54+
bias_regularizer: null
55+
kernel_constraint: null
56+
kernel_initializer:
57+
class_name: RandomUniform
58+
config: {maxval: 0.05, minval: -0.05, seed: null}
59+
kernel_regularizer: null
60+
name: dense_3
61+
trainable: true
62+
units: !!python/object/apply:numpy.core.multiarray.scalar
63+
- !!python/object/apply:numpy.dtype
64+
args: [i8, 0, 1]
65+
state: !!python/tuple [3, <, null, null, null, -1, -1, 0]
66+
- !!binary |
67+
AgAAAAAAAAA=
68+
use_bias: true
69+
keras_version: 2.0.4
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"backend": "tensorflow", "class_name": "Sequential", "config": [{"class_name": "Dense", "config": {"kernel_constraint": null, "bias_initializer": {"class_name": "Zeros", "config": {}}, "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"mode": "fan_avg", "distribution": "uniform", "scale": 1.0, "seed": null}}, "activation": "relu", "batch_input_shape": [null, 20], "activity_regularizer": null, "bias_regularizer": null, "bias_constraint": null, "name": "dense_1", "units": 64, "dtype": "float32", "trainable": true, "kernel_regularizer": null}}, {"class_name": "Dropout", "config": {"rate": 0.5, "name": "dropout_1", "trainable": true}}, {"class_name": "Dense", "config": {"kernel_constraint": null, "bias_constraint": null, "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"mode": "fan_avg", "distribution": "uniform", "scale": 1.0, "seed": null}}, "activation": "relu", "name": "dense_2", "activity_regularizer": null, "bias_regularizer": null, "bias_initializer": {"class_name": "Zeros", "config": {}}, "units": 64, "trainable": true, "kernel_regularizer": null}}, {"class_name": "Dropout", "config": {"rate": 0.5, "name": "dropout_2", "trainable": true}}, {"class_name": "Dense", "config": {"kernel_constraint": null, "bias_constraint": null, "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"mode": "fan_avg", "distribution": "uniform", "scale": 1.0, "seed": null}}, "activation": "softmax", "name": "dense_3", "activity_regularizer": null, "bias_regularizer": null, "bias_initializer": {"class_name": "Zeros", "config": {}}, "units": 10, "trainable": true, "kernel_regularizer": null}}], "keras_version": "2.0.4"}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
backend: tensorflow
2+
class_name: Sequential
3+
config:
4+
- class_name: Dense
5+
config:
6+
activation: relu
7+
activity_regularizer: null
8+
batch_input_shape: !!python/tuple [null, 20]
9+
bias_constraint: null
10+
bias_initializer:
11+
class_name: Zeros
12+
config: {}
13+
bias_regularizer: null
14+
dtype: float32
15+
kernel_constraint: null
16+
kernel_initializer:
17+
class_name: VarianceScaling
18+
config: {distribution: uniform, mode: fan_avg, scale: 1.0, seed: null}
19+
kernel_regularizer: null
20+
name: dense_1
21+
trainable: true
22+
units: 64
23+
use_bias: true
24+
- class_name: Dropout
25+
config: {name: dropout_1, rate: 0.5, trainable: true}
26+
- class_name: Dense
27+
config:
28+
activation: relu
29+
activity_regularizer: null
30+
bias_constraint: null
31+
bias_initializer:
32+
class_name: Zeros
33+
config: {}
34+
bias_regularizer: null
35+
kernel_constraint: null
36+
kernel_initializer:
37+
class_name: VarianceScaling
38+
config: {distribution: uniform, mode: fan_avg, scale: 1.0, seed: null}
39+
kernel_regularizer: null
40+
name: dense_2
41+
trainable: true
42+
units: 64
43+
use_bias: true
44+
- class_name: Dropout
45+
config: {name: dropout_2, rate: 0.5, trainable: true}
46+
- class_name: Dense
47+
config:
48+
activation: softmax
49+
activity_regularizer: null
50+
bias_constraint: null
51+
bias_initializer:
52+
class_name: Zeros
53+
config: {}
54+
bias_regularizer: null
55+
kernel_constraint: null
56+
kernel_initializer:
57+
class_name: VarianceScaling
58+
config: {distribution: uniform, mode: fan_avg, scale: 1.0, seed: null}
59+
kernel_regularizer: null
60+
name: dense_3
61+
trainable: true
62+
units: 10
63+
use_bias: true
64+
keras_version: 2.0.4
Binary file not shown.
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<?eclipse version="3.0"?>
3+
<plugin>
4+
<extension point="org.knime.testing.TestcaseCollector">
5+
<TestcaseCollector
6+
TestcaseCollector="org.knime.dl.keras.testing.DLKerasTestCaseCollector">
7+
</TestcaseCollector>
8+
</extension>
9+
</plugin>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/*
2+
* ------------------------------------------------------------------------
3+
*
4+
* Copyright by KNIME GmbH, Konstanz, Germany
5+
* Website: http://www.knime.org; Email: [email protected]
6+
*
7+
* This program is free software; you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License, Version 3, as
9+
* published by the Free Software Foundation.
10+
*
11+
* This program is distributed in the hope that it will be useful, but
12+
* WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program; if not, see <http://www.gnu.org/licenses>.
18+
*
19+
* Additional permission under GNU GPL version 3 section 7:
20+
*
21+
* KNIME interoperates with ECLIPSE solely via ECLIPSE's plug-in APIs.
22+
* Hence, KNIME and ECLIPSE are both independent programs and are not
23+
* derived from each other. Should, however, the interpretation of the
24+
* GNU GPL Version 3 ("License") under any applicable laws result in
25+
* KNIME and ECLIPSE being a combined program, KNIME GMBH herewith grants
26+
* you the additional permission to use and propagate KNIME together with
27+
* ECLIPSE with only the license terms in place for ECLIPSE applying to
28+
* ECLIPSE and the GNU GPL Version 3 applying for KNIME, provided the
29+
* license terms of ECLIPSE themselves allow for the respective use and
30+
* propagation of ECLIPSE together with KNIME.
31+
*
32+
* Additional permission relating to nodes for KNIME that extend the Node
33+
* Extension (and in particular that are based on subclasses of NodeModel,
34+
* NodeDialog, and NodeView) and that only interoperate with KNIME through
35+
* standard APIs ("Nodes"):
36+
* Nodes are deemed to be separate and independent programs and to not be
37+
* covered works. Notwithstanding anything to the contrary in the
38+
* License, the License does not apply to Nodes, you are not required to
39+
* license Nodes under the License, and you are granted a license to
40+
* prepare and propagate Nodes, in each case even if such Nodes are
41+
* propagated with or for interoperation with KNIME. The owner of a Node
42+
* may freely choose the license terms applicable to such Node, including
43+
* when such Node is propagated with or for interoperation with KNIME.
44+
* ---------------------------------------------------------------------
45+
*
46+
* History
47+
* May 23, 2017 (marcel): created
48+
*/
49+
package org.knime.dl.keras.testing;
50+
51+
import java.io.IOException;
52+
import java.net.MalformedURLException;
53+
import java.net.URL;
54+
import java.nio.file.InvalidPathException;
55+
import java.util.Collections;
56+
import java.util.HashMap;
57+
import java.util.Map;
58+
import java.util.Set;
59+
import java.util.function.Consumer;
60+
61+
import org.junit.Test;
62+
import org.knime.core.util.FileUtil;
63+
import org.knime.dl.core.DLLayerData;
64+
import org.knime.dl.core.DLLayerDataSpec;
65+
import org.knime.dl.core.data.writables.DLWritableFloatBuffer;
66+
import org.knime.dl.core.execution.DLLayerDataInput;
67+
import org.knime.dl.core.execution.DLLayerDataOutput;
68+
import org.knime.dl.keras.core.DLKerasDefaultBackend;
69+
import org.knime.dl.keras.core.DLKerasExecutableNetwork;
70+
import org.knime.dl.keras.core.DLKerasExecutableNetwork.DLKerasExecutableNetworkSpec;
71+
import org.knime.dl.keras.core.DLKerasNetwork;
72+
import org.knime.dl.keras.core.io.DLKerasNetworkReader;
73+
import org.knime.dl.util.DLUtils;
74+
75+
/**
76+
*
77+
* @author Marcel Wiedenmann, KNIME, Konstanz, Germany
78+
* @author Christian Dietz, KNIME, Konstanz, Germany
79+
*/
80+
public class DLKerasNetworkExecutor1To1Test {
81+
82+
private static final String BUNDLE_ID = "org.knime.dl.keras.testing";
83+
84+
@Test
85+
public void test() throws IOException, InvalidPathException, MalformedURLException {
86+
final URL source =
87+
FileUtil.toURL(DLUtils.Files.getFileFromBundle(BUNDLE_ID, "data/my_2d_input_model.h5").getAbsolutePath());
88+
89+
final DLKerasDefaultBackend backend = new DLKerasDefaultBackend();
90+
final DLKerasNetworkReader reader = backend.createReader();
91+
DLKerasNetwork network;
92+
try {
93+
network = reader.readNetwork(source);
94+
} catch (IllegalArgumentException | IOException e) {
95+
throw new RuntimeException(e);
96+
}
97+
final DLKerasExecutableNetwork execNetwork = backend.toExecutableNetwork(network);
98+
final DLKerasExecutableNetworkSpec execSpec = execNetwork.getSpec();
99+
100+
final HashMap<DLLayerDataSpec, ?> inputs = new HashMap<>(execSpec.getInputSpecs().length);
101+
for (final DLLayerDataSpec inputSpec : execSpec.getInputSpecs()) {
102+
final DLLayerDataInput<?> input = execNetwork.getInputForSpec(inputSpec, 1);
103+
populate(input.getBatch()[0]);
104+
}
105+
final Set<DLLayerDataSpec> selectedOutputs = Collections.singleton(execSpec.getOutputSpecs()[0]);
106+
107+
execNetwork.execute(selectedOutputs, new Consumer<Map<DLLayerDataSpec, DLLayerDataOutput<?>>>() {
108+
109+
@Override
110+
public void accept(final Map<DLLayerDataSpec, DLLayerDataOutput<?>> t) {
111+
// TODO: test against known results - this is sth. that should rather be tested via a test workflow
112+
}
113+
});
114+
}
115+
116+
private static void populate(final DLLayerData<?> data) {
117+
if (data.getBuffer() instanceof DLWritableFloatBuffer) {
118+
final DLWritableFloatBuffer buffer = (DLWritableFloatBuffer)data.getBuffer();
119+
buffer.resetWrite();
120+
for (int i = 0; i < buffer.getCapacity(); i++) {
121+
buffer.put(5f);
122+
}
123+
} else {
124+
throw new IllegalStateException("Unexpected input buffer type.");
125+
}
126+
}
127+
}

0 commit comments

Comments
 (0)