deeplearning4j-examples
deeplearning4j-examples copied to clipboard
Mixture Density example
From stack overflow here
I have built and trained a Mixed Density Network with Keras mostly following this medium post which contains an implementation of the mean negative log-likelihood to be used as the loss function. Now I want to load the trained model (both the structure of the net and the weights) on DL4J to serve the predictions but I get the runtime error: UnsupportedKerasConfigurationException: Unknown Keras loss function.
I was expecting this since the loss function isn't embedded in Keras, however I see DL4J has it's own LossMixtureDensity for this purpose, contained in the package org.deeplearning4j.nn.modelimport.keras.utils, but I don't know how to bind my custom loss function to it. Is there any way to do it?
As a second choice alternative, I was thinking about writing a "twin" MDN directly in DL4J and then just loading the trained weights, but it's my first time with DL4J and I'm not sure on how to do it: my output layer concatenates the coefficients of the mixture, the means and standard deviations with different activation functions, while the example provided in the deeplearning4j-examples repository seems to use a simple identity activation. Honestly I can't even understand how the example can work without e.g. imposing a softmax activation for the mixing coefficients.