CoolFace
Apppublic

HumanCenteredAI/olliedetection

sourceHugging Faceupdated 11mo agoView on Hugging Face
0likes
attention.py13 linesDownload Raw Back to root
1from tensorflow.keras.layers import Layer2from tensorflow.keras import backend as K3 4class Attention(Layer):5    def build(self, input_shape):6        self.W = self.add_weight(shape=(input_shape[-1], 1), initializer="random_normal", trainable=True)7        self.b = self.add_weight(shape=(input_shape[1], 1), initializer="zeros", trainable=True)8 9    def call(self, x):10        e = K.tanh(K.dot(x, self.W) + self.b)11        a = K.softmax(e, axis=1)12        return K.sum(x * a, axis=1)13