From e4edc68df5f6deb23560a7d16ed3b1cf51c1c9fa Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Wed, 31 Aug 2022 18:52:35 +0100 Subject: [PATCH] ai: add missing gamma layer --- .../lib/ai/components/LayerConvNeXtGamma.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 aimodel/src/lib/ai/components/LayerConvNeXtGamma.py diff --git a/aimodel/src/lib/ai/components/LayerConvNeXtGamma.py b/aimodel/src/lib/ai/components/LayerConvNeXtGamma.py new file mode 100644 index 0000000..f0b8ec0 --- /dev/null +++ b/aimodel/src/lib/ai/components/LayerConvNeXtGamma.py @@ -0,0 +1,20 @@ +import tensorflow as tf + +# Code from https://github.com/leanderme/ConvNeXt-Tensorflow/blob/main/ConvNeXt.ipynb + +class LayerConvNeXtGamma(tf.keras.layers.Layer): + def __init__(self, const_val = 1e-6, dim = None, name=None, **kwargs): + super(LayerConvNeXtGamma, self).__init__(name=name) + + self.dim = dim + self.const = const_val * tf.ones((self.dim)) + + def call(self, inputs, **kwargs): + return tf.multiply(inputs, self.const) + + def get_config(self): + config = super(LayerConvNeXtGamma, self).get_config() + + config.update({ "const": self.const, "dim": self.dim }) + + return config