title: Bridging Knime, Keras and DL4J – Exceptions when loading h5 model
body: <p>I’m working on a project which needs to train a DNN and then run the trained model in a Java environment. As the training data requires a lot of manipulation I’ve used Knime and its Keras libraries to do most of the work, and I’m exported the trained model to a Keras h5 file which can be loaded into DL4J (I’m using Knime Keras Integration 4.1.0v201911171432 and DL4J 1.0.0-beta6).</p>
  
  <p>The modelling is ongoing, but for a POC I’ve created a network by chaining the following nodes:</p>
  
  <ul>
  <li>Keras Input Layer (shape 144)</li>
  <li>Keras Dense Layer (units 500)</li>
  <li>Keras Dense Layer (units 500)</li>
  <li>Keras Dense Layer (units 1)</li>
  <li>Keras Set Output Layers (single output shape [1] pointing to the last layer)</li>
  </ul>
  
  <p>This then gets trained and outputted with a “Keras Network Writer” node which writes a .h5 file.</p>
  
  <p>In Java I have includes the following dependencies:</p>
  
  <pre><code> &lt;dependency&gt;
        &lt;groupId&gt;org.deeplearning4j&lt;/groupId&gt;
        &lt;artifactId&gt;deeplearning4j-core&lt;/artifactId&gt;
        &lt;version&gt;1.0.0-beta6&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
        &lt;groupId&gt;org.nd4j&lt;/groupId&gt;
        &lt;artifactId&gt;nd4j-native-platform&lt;/artifactId&gt;
        &lt;version&gt;1.0.0-beta6&lt;/version&gt;
      &lt;/dependency&gt;
  </code></pre>
  
  <p>And run the following code:</p>
  
  <pre><code>import org.deeplearning4j.nn.modelimport.keras.KerasModelImport;
  …
  ComputationGraph model = KerasModelImport.importKerasModelAndWeights("2x2x2keras.h5");
  </code></pre>
  
  <p>Which returns the following exception</p>
  
  <pre><code>java.lang.IllegalStateException: Invalid configuration: network has no outputs. Use .setOutput(String...) to specify (and give an ordering to) the output vertices, or use allowNoOutputs(true) to disable this check
      at org.deeplearning4j.nn.conf.ComputationGraphConfiguration.validate(ComputationGraphConfiguration.java:375) ~[deeplearning4j-nn-1.0.0-beta6.jar:na]
      at org.deeplearning4j.nn.conf.ComputationGraphConfiguration$GraphBuilder.build(ComputationGraphConfiguration.java:1197) ~[deeplearning4j-nn-1.0.0-beta6.jar:na]
      at org.deeplearning4j.nn.modelimport.keras.KerasModel.getComputationGraphConfiguration(KerasModel.java:394) ~[deeplearning4j-modelimport-1.0.0-beta6.jar:na]
      at org.deeplearning4j.nn.modelimport.keras.KerasModel.getComputationGraph(KerasModel.java:415) ~[deeplearning4j-modelimport-1.0.0-beta6.jar:na]
      at org.deeplearning4j.nn.modelimport.keras.KerasModel.getComputationGraph(KerasModel.java:404) ~[deeplearning4j-modelimport-1.0.0-beta6.jar:na]
      at org.deeplearning4j.nn.modelimport.keras.KerasModelImport.importKerasModelAndWeights(KerasModelImport.java:173) ~[deeplearning4j-modelimport-1.0.0-beta6.jar:na]
      at dev.aisandbox.tftest.TFRunner.run(TFRunner.java:18) ~[classes/:na]
  </code></pre>
  
  <p>As this is the first time I’ve tried using Knime to manage my dataflow, I can’t be certain if the issues is with the file (being created in Knime) or the code loading it (into DL4J+Java). I’m assuming the comment about setOutput is intended for when you are creating the network with a python script, but can’t see anyway to set allowNoOutputs when KerasModelImport only has static methods.</p>