Skip to content

Commit

Permalink
Merge pull request fastmachinelearning#1009 from vloncar/fix_ext_test_v3
Browse files Browse the repository at this point in the history
Fix extension test for Keras v3
  • Loading branch information
jmitrevs authored May 3, 2024
2 parents ed55394 + 863c57b commit 28f158d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/advanced/extension.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ For concreteness, let's say our custom layer ``KReverse`` is implemented in Kera
def call(self, inputs):
return tf.reverse(inputs, axis=[-1])
def get_config(self):
return super().get_config()
Make sure you define a ``get_config()`` method for your custom layer as this is needed for correct parsing.
We can define the equivalent layer in hls4ml ``HReverse``, which inherits from ``hls4ml.model.layers.Layer``.

.. code-block:: Python
Expand Down
4 changes: 4 additions & 0 deletions test/pytest/test_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ def __init__(self):
def call(self, inputs):
return tf.reverse(inputs, axis=[-1])

def get_config(self):
# Breaks serialization and parsing in hls4ml if not defined
return super().get_config()


# hls4ml layer implementation
class HReverse(hls4ml.model.layers.Layer):
Expand Down

0 comments on commit 28f158d

Please sign in to comment.