Created
November 17, 2021 05:47
-
-
Save rohan-paul/b035ccfebf313bcc961650b7a8837296 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tensorflow import keras | |
import tensorflow as tf | |
class ChildDense(keras.layers.Layer): | |
def __init__(self, units, activation=None): | |
super().__init__() | |
self.units = units | |
self.activation = activation | |
def build(self, input_shape): | |
# Shape of the input data is referred by input_shape. | |
input_dim = input_shape[-1] | |
self.W = self.add_weight(shape=(input_dim, self.units), initializer='random_normal') | |
self.b = self.add_weight(shape=(self.units, ), initializer='zeros') | |
def call(self, inputs): | |
y = tf.matmul(inputs, self.W) + self.b | |
if self.activation is not None: | |
y = self.activation(y) | |
return y |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment