I have some problems importing my custom layer into my Java project. I read the documentation (https://deeplearning4j.konduit.ai/keras-import/custom-layers) but without succes. I’ve seen the two examples but it isn’t clear for me how to exactly implement my method in Java, like what should I implement etc?
This is the python code:
class lstm_bottleneck(tf.keras.layers.Layer):
def __init__(self, lstm_units, time_steps, **kwargs):
self.lstm_units = lstm_units
self.time_steps = time_steps
self.lstm_layer = Bidirectional(LSTM(lstm_units, return_sequences=False))
self.repeat_layer = RepeatVector(time_steps)
super(lstm_bottleneck, self).__init__(**kwargs)
def call(self, inputs):
# just call the two initialized layers
return self.repeat_layer(self.lstm_layer(inputs))
def compute_mask(self, inputs, mask=None):
# return the input_mask directly
return mask
def get_config(self):
thisDict = {
"lstm_layer": self.lstm_layer.get_config(),
"repeat_layer": self.repeat_layer.get_config()
}
return thisDict
And this is my Java code. Ofcourse it isn’t working because i’m just trying to get the examples given in the documentation… (lstm_units and time_steps are fixed numbers so i guess i shouldn’t implement that in the get_config() method).
public class lstm_bottleneck extends KerasLayer {
private int lstm_units = 45;
private int time_steps = 322;
public lstm_bottleneck(Map<String, Object> layerconfig)
throws InvalidKerasConfigurationException, UnsupportedKerasConfigurationException {
this(layerconfig, true);
}
public lstm_bottleneck(Map<String, Object> layerconfig, boolean enforceTrainingConfig)
throws InvalidKerasConfigurationException, UnsupportedKerasConfigurationException{
super(layerconfig, enforceTrainingConfig);
Map<String, Object> lrnParams = KerasLayerUtils.getInnerLayerConfigFromConfig(layerconfig, conf);
}
}
Anyone who can help? Thanks in advance!!