Repository: deeplearning4j/deeplearning4j
Issue: Keras Model Import API Loss Layer inconsistencies

#### Issue Description
KerasModelImport.importKerasModelAndWeights(modelFileName, enforceTrain) vs 
KerasModelImport.importKerasModelAndWeights(jsonConfig, weightsFile, enforceTrain)

produces different results (one includes a Loss Layer to the tail while the other does not):
Reference the following gist for summary output:
https://gist.github.com/akamlani/3a73df77fc1d3cbbc09101ba560a5efc

In addition, it also is unable to handle the Loss Layer:
Reference the following Keras gist for model architecture:
https://gist.github.com/akamlani/f0371c3f91ad3e809a706b026bbf8ddb
```
KerasModel - Model cannot be trained: output layer outputLayer_a_loss is not an IOutputLayer (no loss function specified)
KerasModel - Model cannot be trained: output outputLayer_a_loss is not an IOutputLayer (no loss function specified)
```
Unable to perform training nor inference, as no Output Layer recognized.

#### Version Information
* 0.9.2-SNAPSHOT (Per 11/12)
* Keras 2.0.7 + TensorFlow 1.3.0
* MacOS
* CPU Based



Changed files:
deeplearning4j-modelimport/src/main/java/org/deeplearning4j/nn/modelimport/keras/KerasModel.java
deeplearning4j-modelimport/src/test/java/org/deeplearning4j/nn/modelimport/keras/e2e/KerasModelEndToEndTest.java

diff --git a/deeplearning4j-modelimport/src/main/java/org/deeplearning4j/nn/modelimport/keras/KerasModel.java b/deeplearning4j-modelimport/src/main/java/org/deeplearning4j/nn/modelimport/keras/KerasModel.java
index 1b23683f2f..90f57bdef0 100644
--- a/deeplearning4j-modelimport/src/main/java/org/deeplearning4j/nn/modelimport/keras/KerasModel.java
+++ b/deeplearning4j-modelimport/src/main/java/org/deeplearning4j/nn/modelimport/keras/KerasModel.java
@@ -158,8 +158,12 @@ public class KerasModel {
         prepareLayers((List<Object>) layerLists.get((config.getModelFieldLayers())));
 
         /* Import training configuration. */
-        if (trainingJson != null && enforceTrainingConfig)
-            importTrainingConfiguration(trainingJson);
+        if (enforceTrainingConfig) {
+            if (trainingJson != null)
+                importTrainingConfiguration(trainingJson);
+            else throw new UnsupportedKerasConfigurationException("If enforceTrainingConfig is true, a training " +
+                    "configuration object (JSON) has to be provided.");
+        }
 
         /* Infer output types for each layer. */
         inferOutputTypes(inputShape);
diff --git a/deeplearning4j-modelimport/src/test/java/org/deeplearning4j/nn/modelimport/keras/e2e/KerasModelEndToEndTest.java b/deeplearning4j-modelimport/src/test/java/org/deeplearning4j/nn/modelimport/keras/e2e/KerasModelEndToEndTest.java
index 8d0cf1d141..dc1c7e9a08 100644
--- a/deeplearning4j-modelimport/src/test/java/org/deeplearning4j/nn/modelimport/keras/e2e/KerasModelEndToEndTest.java
+++ b/deeplearning4j-modelimport/src/test/java/org/deeplearning4j/nn/modelimport/keras/e2e/KerasModelEndToEndTest.java
@@ -287,6 +287,30 @@ public class KerasModelEndToEndTest {
         importFunctionalModelH5Test("modelimport/keras/examples/reshape_to_rnn/reshape_model.h5");
     }
 
+    /**
+     * Functional LSTM test
+     */
+    @Test
+    public void importFunctionalLstmTfKeras2() throws Exception {
+        String modelPath = "modelimport/keras/examples/functional_lstm/lstm_functional_tf_keras_2.h5";
+
+        // No training enabled
+        ComputationGraph graphNoTrain = importFunctionalModelH5Test(modelPath, null, false);
+        System.out.println(graphNoTrain.summary());
+
+        // Training enabled
+        ComputationGraph graph = importFunctionalModelH5Test(modelPath, null, true);
+        System.out.println(graph.summary());
+
+        // Make predictions
+        int miniBatch = 32;
+        INDArray input = Nd4j.ones(miniBatch, 4, 10);
+        INDArray[] out = graph.output(input);
+
+        // Fit model
+        graph.fit(new INDArray[] {input}, out);
+    }
+
     /**
      * U-Net
      */