# Creating custom layer in java Deeplearning4J

**URL:** <https://community.konduit.ai/t/creating-custom-layer-in-java-deeplearning4j/1122>\
**Category:** DL4J\
**Created:** [January 14, 2021, 8:51am UTC](https://community.konduit.ai/t/creating-custom-layer-in-java-deeplearning4j/1122 "2021-01-14T08:51:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![DataPlanningEngineer](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/dataplanningengineer/32/435_2.png) [@DataPlanningEngineer](https://community.konduit.ai/u/DataPlanningEngineer)\
**Post date:** [January 14, 2021, 8:51am UTC](https://community.konduit.ai/t/creating-custom-layer-in-java-deeplearning4j/1122/1 "2021-01-14T08:51:33Z")

</div>

I have some problems importing my custom layer into my Java project. I read the documentation ([https://deeplearning4j.konduit.ai/keras-import/custom-layers](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:

```auto
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).

```auto
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!!

---

<div class="post-metadata">

**Author:** ![agibsonccc](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/agibsonccc/32/697_2.png) [@agibsonccc](https://community.konduit.ai/u/agibsonccc)\
**Post date:** [January 14, 2021, 9:28am UTC](https://community.konduit.ai/t/creating-custom-layer-in-java-deeplearning4j/1122/2 "2021-01-14T09:28:21Z")

</div>

@DataPlanningEngineer did you respond to my comment on github earlier? I actually replied to you. Happy to continue the discussion here if you’d like.
